In the following program, the class 'Card' has a vector of Class1's, and an object of Class1 inside of it. In Card's constructor, I've been able to assign the other variables easily, but have run into errors whenever trying to construct class1_object and class1_vector. I feel like there is probably some sort of method for doing this, and am hoping that somebody here may have the answer I'm looking for:
Class1 is unusable in the code you posted. The only things you can do with it are construct it with no arguments and copy it around. If you make var01 public, you can assign to it like this:
1 2
Class1 c;
c.var01 = 5;
You really should write a constructor for Class1 as well. Right now all you can do is declare it as above with no arguments.
Card( std::string sui = "", int num = 0 )
{
suit = sui;
number = num;
for (auto i = 0; i < 10; ++i)
class1_vector.at(i) = new Class1; // fill with 10 Class1 objects
}
~Card()
{
for (short i = 0; i < 10; ++i)
delete class1_vector.at(i);
}
As for Class1 object inside the class Card the object is constructed for you for free, no aditional action is required according to your Class1 declaration.
If you can be more specific as what is you goal here maybe someone can help u.