I have
Code:class A{ ... A(int x,int y){ } ... } class B{ A a; ....} in class B constructor, I want to initialize a with value 4 and 5. How can I do that? I tried this A a(4,5); but I dont think it is correct.
This is a discussion on Help within the C++ Programming forums, part of the General Programming Boards category; I have Code: class A{ ... A(int x,int y){ } ... } class B{ A a; ....} in class B ...
I have
Code:class A{ ... A(int x,int y){ } ... } class B{ A a; ....} in class B constructor, I want to initialize a with value 4 and 5. How can I do that? I tried this A a(4,5); but I dont think it is correct.
Like this:
Code:a = A(4,5);
Manasij Mukherjee | gcc-4.8.0 @Arch Linux
Slow and Steady wins the race... if and only if :
1.None of the other participants are fast and steady.
2.The fast and unsteady suddenly falls asleep while running !
I am getting this error:
IntelliSense: no default constructor exists for class "A"
I am getting this error because I dont have an empty constructor for class A?
Back to the OP, use an initialiser list in the definition of B's constructor.
Assuming we're implementing B's default constructor.
Code:B::B() : a(4,5) { // job done }
Right 98% of the time, and don't care about the other 3%.