This is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <iostream>
using namespace std;
class farm_animals
{
public:
struct cow
{
int value;
};
cow myCow;
};
farm_animals farm_object;
farm_object.myCow.value = 10; //this line dosnt work
int main(){
cin.ignore();
return 0;
}
|
whenever i try to change the value of lets say myCow.value it comes up with the same errors ive had before, it dosnt matter if i do this:
1 2 3 4 5 6 7 8 9
|
class farm_animals
{
public:
struct cow
{
int value;
};
cow myCow;
};
|
and create myCow inside the class it comes up with same errors, maybe its becasue of the way i change the myCow.value. I dont know what to type, should i type:
1 2 3
|
farm_animals farm_object; //create object for class
farm_object::cow myCow; //create instance of the cow structure called myCow
farm_object.myCow.value = 10; //change the myCow instance's "int value" to 10
|
that dosnt work.
or should i create cow instance inside the class, becasue nothing i do works, it always comes up with: syntax error : missing ';' before '.'
i have been trying to fix it for 2 days now and im getting sick of the same problem, I had a whole game that had 3 different files and it didnt work, so i made a more simple verson so i could see directly what the problem was, but no matter what i do the only way the program will run is if I dont change the value, everything else works.
This is what I think the problem is.... I think i dont correctly know the right syntax for changing the value, i thought it was this.
|
farm_object.myCow.value = 10;
|
the farm_object for the class object, myCow for the cow structure instance and value for the "int value;" in the structure for cow.
Maybe the syntax is more complicated, but its very specific so there is very little information about this online, I just need C++ experts who have been doing C++ for long enough to understand what im doing wrong.