Questions tagged [in-class-initialization]
55 questions
0
votes
2 answers
Why C++ does allow in-class definition?
Does in-class definition break the ODR rule?
Bjarne Stroustrup's explanation states this:
A class is typically declared in a header file and a header file is typically included into many translation units. However, to avoid complicated linker…

mada
- 1,646
- 1
- 15
0
votes
0 answers
Difference between = and {} in-class initialization
When I want t put initial values inside the class definition there are two ways it can be done: with {} and =
class A
{
public:
int a = 1;
bool b = false;
someClass* obj = nullptr;
};
class B
{
public:
int a {1};
bool b {false};
…

Bruice
- 63
- 6
0
votes
1 answer
Class Initialization of a list of empty lists not updating
I have a list that is made up of 4 deques with a set length. I have made that list with the hope that it will update as the other ones. Here is a simple example:
class foo():
def __init__(self):
self.buffer_size = 300
self.a =…

Amanda.py
- 113
- 10
0
votes
1 answer
Class initialization failing
# Class and Instance Variables
class Dog:
kind = 'canine'
def __int__(self, name):
self.name = name
self.tricks = []
d = Dog('Fido')
e = Dog('Buddy')
print(d.kind)
print(e.kind)
print(d.name)
print(e.name)
Error…

chentaocuc
- 177
- 1
- 2
- 8
0
votes
1 answer
Initializing Class Properties In Swift
So I'm trying to create a Playground that functions as a 'presentation', meaning that I have multiple slides and it's interactive-ish. I'm new to Swift, so would really use some help.
This is my main code
import UIKit
import SpriteKit
import…

Austin
- 21
- 3
0
votes
1 answer
C++ in-class initialization
When using in-class initializers, why can I use the copy form of initialization '=' and the braced list form of initialization '{}' but no direct form '()'.
class foo{
int a = 5;
int b{5};
int c(5);
};
Error: expected a type…
user5249738
0
votes
1 answer
In-class member initializer of unique_ptr to nullptr error with explicitly defined default constructor
I have a class template that assigns a unique_ptr to nullptr using an in-class member initializer. If I use MyClass(){}, all is well. If I use MyClass() = default, I get:
conversion from 'std::nullptr_t' to non-scalar type 'std::unique_ptr'…

David Doria
- 9,873
- 17
- 85
- 147
0
votes
2 answers
Order in which fields in a bean are initialized
I have a bean like this:
@Component
@DependsOn("SomeType")
Class A{
@Autowired
SomeType one;
String two = one.someMethod();
int three;
}
In my application context xml, I have:

broun
- 2,483
- 5
- 40
- 55
-1
votes
1 answer
Is the initializer for a const static data member considered a default member initializer?
Is the initializer for a const static data member considered a default member initializer?
The relevant wording is [class.mem.general]/10:
A brace-or-equal-initializer shall appear only in the declaration of a
data member. (For static data members,…
user20175049
-4
votes
1 answer
ISO C++ forbids member initialization within a struct
I'm writing an emulator and decided to control input/output emulation within a struct:
struct callbacks
{
short LastFrequency = 9000;
int *MMIO_RANGE1;
short Cycle_LN = 65535 / LastFrequency;
const char *STATUS_FLAGS[] =
{
"ACK",
…

USER LEVEL ORGANISM
- 25
- 2