Calling a class function error

So just for fun, I'm creating a text-based game. However, I've run into a problem with the character choice.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int response;
int myChoice;
int section=0;
int bug=0;

while(myChoice==0)
{
cout<<"The start of your journey begins in the training hall"<<endl;
cout<<"Here in the training hall you can choose the type of character you want to be"<<endl;
cout<<"There are three different classes you can be"<<endl;
cout<<"Enter '1' for a warrior-soldier"<<endl;
cout<<"		a warrior-knight has higher strength"<<endl;
cout<<"Enter '2' for a mage"<<endl;
cout<<"		a mage has higher inteligence"<<endl;
cout<<"Enter '3' for a theif"<<endl;
cout<<"		a theif has higher speed"<<endl;
cin>>myChoice;
story.choose(myChoice);
}


Unfortunately, story.choose(myChoice); gives me an error for (myChoice), the error that it gives me is "myChoice is not a type name." Also, the period gives me the error "expected an identifier." (story.choose(myChoice); is from story.h)

This is story.h:
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
#include <iostream>

using namespace std;

class story
{
private:
	int choice;
	int storySection;
	int type;
public:

	void choose(int choice)
	{
		if(choice==1)
			type=1;
		if(choice==2)
			type=2;
		if(choice==3)
			type=3;
	}

	void warrior();
	void mage();
	void theif();
};

This is an invalid statement

story.choose(myChoice);

It is not C#. It is C++ and function choose is not a static function. The correct syntax is

ObjectOfTypestory.choose(myChoice);
I'm trying to code it in C++. Have I coded the class in C#?
You shall use the correct C++ syntax for accessing class members.
Have I not used the correct C++ syntax?
Last edited on
you need to declare an instance of you class in the main program
1
2
3
4
5
story s;

....

s.choose(myChoice);
Last edited on
Topic archived. No new replies allowed.