Questions tagged [member-initialization]
121 questions
0
votes
2 answers
What is the use of member initializers list in constructors?
I was trying to understand the concept of operator overloading, but can't understand the use of member initializer lists in this program. What is their real use, and could I rewrite this program without them ?
#include
using namespace…

user2439492
- 91
- 1
- 2
- 8
0
votes
1 answer
Class with std::istream reference initialization
I'm having problems initializing this class:
class Player{
///
std::istream ∈
///
};
Trying like this:
Player::Player():in(cin){
///
}
Can anyone point me in the right direction of how to accomplish this?
Also, after initialization, can…

Nicholas Paxton
- 3
- 3
0
votes
1 answer
Is using null to declare literal members for later initialization a viable praxis in JS?
I'm going to declare a literal as follows:
var obj = {
x: null,
init: function (pX) {
this.x = pX;
}
};
Objections?
I'd like to do that because x: undefined would be the same as not declaring x at all. Whats a good practice when…

sirrk
- 31
- 1
- 9
0
votes
4 answers
How to refrain from CS2512 correctly
Please help me with the following problem:
I have the following classes:
class ChemicalElement
{
private:
std::string _name;
void Init(const std::string& name);
public:
ChemicalElement(const std::string& name);
ChemicalElement(const…

Ikaso
- 2,268
- 19
- 26
0
votes
3 answers
Error C2064 using and
I really don't know what to do here. Every answer I look up has syntax that I just don't understand.
error:
Error 1 error C2064: term does not evaluate to a function taking 1 arguments
I'm using a function pointer in a hash table constructor. It…

rearden
- 135
- 1
- 1
- 11
0
votes
1 answer
Hash Table not accepting function passed into constructor in member init list
I have a hash table template that I have written for a class. I have a project due that relies on utilizing this hash table. It accepts an unsigned integer value to initialize the number of buckets it has, as well as a hash function to point to. I…

rearden
- 135
- 1
- 1
- 11
0
votes
4 answers
Are there two types of member initializer lists in C++?
I saw two different ways to use member initializer lists. The first one is like that:
class ClassName {
public:
arg_type_1 varName1;
arg_type_2 varName2;
// Constructor.
ClassName(arg_type_1 arg_name_1, arg_type_2…

Roman
- 124,451
- 167
- 349
- 456
0
votes
5 answers
c++ "new" keyword comparision to java
first of all i hope this isnt a dublicate. Im am a java programmer and changing to c++ now.
In java you can do like this
Object obj = new Object();
and to my understanding you can the same thing in c++ (seeing how obj in java will only be saved in…

Fredrik Boston Westman
- 349
- 1
- 6
- 16
-1
votes
1 answer
I need to call a void function in the middle of a constructors member initializer list so that other objects can be initialized correctly
Here is my constructor.
SceneContainer::SceneContainer()
:
m_BVH(Allshapes, 0)
{
ParseJSONDataIntoShapeData("ShapeList.json");
}
Here is the scene class declaration.
class SceneContainer{
public:
void…

Henry Keskitalo
- 37
- 4
-1
votes
1 answer
Usage of Uniform Initialization Syntax
If I have a class
class Foo
{
public:
Foo();
Foo(int bar);
private:
int m_bar;
}
What is the difference between these two ways to initialize it's member
Foo::Foo(int bar):
m_bar(bar)
{
}
Foo::Foo(int bar):
m_bar{ bar…

Clay Brooks
- 182
- 1
- 11
-1
votes
1 answer
Error when initializing a member std::array with a brace initializer in gcc
Consider the following example:
#include
template
struct A {
A() {}
};
typedef A B;
struct S {
std::array b;
S() : b{{B()}} {}
};
int main() {
S s;
}
when trying to compile it with g++ 4.6.3 and…

vitaut
- 49,672
- 25
- 199
- 336
-1
votes
2 answers
Initialize more than one non static data member of union
Consider following program which is ill formed according to standard
union Test {
int s{3};
float f;
Test() {}
Test(float f) : f(f) {} // this should be error
};
int main() {
}
C++11 standard N3376 clause 12 section…

Destructor
- 14,123
- 11
- 61
- 126
-1
votes
3 answers
Can we call member function only in member initialization list in c++?
I want provide a class with a member function that will initialize the all member of class separately.
e.g.
#include
using namespace std;
int x = 10;
class my{
public:
my():init{}
int &i;
void init()
{
i =…

balaji
- 1,075
- 3
- 12
- 26
-2
votes
1 answer
What is a disadvantage of initializing a smart pointer data member in a member initializer list?
Let's say there is a class B which has a smart pointer member for a pointer to object of class A. Then, what is a disadvantage of initializing the smart pointer member in a member initializer list? I know that initializing is faster than assignment…

Han
- 625
- 2
- 7
- 25
-2
votes
1 answer
Problem constructing a base class from within a subclass constructor
I have 2 classes. Since Doctor will be considered as Employee, I should be using Employee class functions in Doctor class. Only extra thing that Doctor class has is TITLE. Basically, What I tried is I wanted to send value to Doctor's constructor,set…

Mert Özçelik
- 33
- 1
- 7