This is not homework. I am just trying to understand my error. :(

With this, I produce no errors.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  #include <iostream>

using namespace std;

class exampleClass
{
public:
	void x()
	{
		cout << "This was practice.  Let's make something more complex!\n" << endl;

		system("pause");
	}
};

class stats
{
public:
	int Str()
	{
		cout << "Str: " << endl;
	}
	int Dex()
	{
		cout << "Dex: " << endl;
	}
	int Con()
	{
		cout << "Con: " << endl;
	}
	int Int()
	{
		cout << "Int: " << endl;
	}
	int Wis()
	{
		cout << "Wis: " << endl;
	}
	int Cha()
	{
		cout << "Cha: " << endl;
	}

};

class exampleNumericalClass
{
public:
	int x()
	{
		return 2;
	}
	int z()
	{
		return 5;
	}
};

class character
{
public:
	stats characterStats;
};

int main()
{
	int x;


	exampleClass classPractice;
	classPractice.x();	

	character;

	exampleNumericalClass numericalClassPractice;	
	x=numericalClassPractice.x()+numericalClassPractice.z();

	cout << x << endl;

	system("pause");

	return 0;
}


When I add that I want to call upon the stats within the character class, I get all sorts of problems. Here's what it looks like when I call them:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>

using namespace std;

class exampleClass
{
public:
	void x()
	{
		cout << "This was practice.  Let's make something more complex!\n" << endl;

		system("pause");
	}
};

class stats
{
public:
	int Str()
	{
		cout << "Str: " << endl;
	}
	int Dex()
	{
		cout << "Dex: " << endl;
	}
	int Con()
	{
		cout << "Con: " << endl;
	}
	int Int()
	{
		cout << "Int: " << endl;
	}
	int Wis()
	{
		cout << "Wis: " << endl;
	}
	int Cha()
	{
		cout << "Cha: " << endl;
	}

};

class exampleNumericalClass
{
public:
	int x()
	{
		return 2;
	}
	int z()
	{
		return 5;
	}
};

class character
{
public:
	stats characterStats;

	characterStats.Str();
	characterStats.Dex();
	characterStats.Con();
	characterStats.Int();
	characterStats.Wis();
	characterStats.Cha();
};

int main()
{
	int x;


	exampleClass classPractice;
	classPractice.x();	

	character; I haven't worked this far yet.

	exampleNumericalClass numericalClassPractice;	
	x=numericalClassPractice.x()+numericalClassPractice.z();

	cout << x << endl;

	system("pause");

	return 0;
} 

I get a repeat of error codes:
C2143
C4430
C2228
For all six cases.

Any help with this on WHERE I went wrong would be appreciated. Thanks!
So, I think you have to learn much more about class.
You can use variables and functions in class. I saw you used almost function instead of variables(Don't sure if you intended to do it).

And for the error,
1
2
3
4
5
6
7
8
9
10
11
12
class character
{
public:
	stats characterStats;

	characterStats.Str();
	characterStats.Dex();
	characterStats.Con();
	characterStats.Int();
	characterStats.Wis();
	characterStats.Cha();
};


You can't call function in class structure...
How can I explain it... Just like,
1
2
3
4
printf("Hi"); // error
int main(){
    ...
}


So, if you want to call function, call it using function.
Maybe,
1
2
3
4
5
6
7
8
9
10
11
12
13
class character
{
public:
	stats characterStats;
	character(){
		characterStats.Str();
		characterStats.Dex();
		characterStats.Con();
		characterStats.Int();
		characterStats.Wis();
		characterStats.Cha();
	} // We call this a constructor
};

or
1
2
3
4
5
6
7
8
9
10
11
12
13
class character
{
public:
	stats characterStats;
	void func_name(){
		characterStats.Str();
		characterStats.Dex();
		characterStats.Con();
		characterStats.Int();
		characterStats.Wis();
		characterStats.Cha();
	} // And use this function in main
};


And also, in main.
character; should be character object_name;

Learn more about class,
http://www.cplusplus.com/doc/tutorial/classes/
1
2
3
4
5
6
	characterStats.Str();
	characterStats.Dex();
	characterStats.Con();
	characterStats.Int();
	characterStats.Wis();
	characterStats.Cha();

You need to call it inside of a function not in an arbitrary location.

*edit fixed code tags
Last edited on
Don't worry, you're allowed to ask about homework here, we have to admit we all do (unless you don't have homework) ask about homework.
Last edited on
Topic archived. No new replies allowed.