class A{
private:
int attackPower;
public:
void setPower(){
cout<<attackPower;
}
A(int a)
{
attackPower=a;
}
};
class B{
private:
A eob;
public:
B(A ee)
:eob(ee)
{
}
void show()
{
eob.setPower();
}
};
int main()
{
//A obj(1); What if I never declare this first?
B no(obj); //Is there a way to call B object(which has A object as
//private variable)
no.show();
}
If you want to be able to create an object of type B without passing in an object of type A, then you need to define a default constructor.
Also, I strongly encourage you to adopt a sensible indentation style. It will make it much easier to see the structure of your code, and will help you spot errors more easily.