Hi,
I have been trying to learn C++ and I don't know how to use a struct inside a class, when both the struct and the class have Constructors defined. I'd be grateful if someone can point out where I'm going wrong in the following example.
Thanks a lot.
Code:struct Items{ int qty; Items(int input){qty = input;}//constructor. }; class Basket{ private: Items InBasket; public: Basket(int inval); void GetStuff(); }; Basket::Basket(int inval){ Items(inval); } void Basket::GetStuff(){ cout<<"\nIn basket = "<<InBasket.qty; } int main(void){ Basket B1(5); B1.GetStuff(); return(EXIT_SUCCESS); }



LinkBack URL
About LinkBacks



