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.
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.
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 }