More Help [Archive] - C Board

PDA

View Full Version : More Help


Quantrizi
07-15-2002, 04:53 PM
Ok, I spent 2 days on this problem...for my RPG, when the user chooses a profession, nothing happens, I just get this error:
C:\Program Files\Microsoft Visual Studio\My Projects\RPG2k\main.cpp(54) : error C2679: binary '<' : no operator defined which takes a right-hand operand of type 'const int' (or there is no acceptable conversion)

here's what I do for the prof choice:

void begin()
{
user.proftype == 0;
system("cls");
pcol();
cout << "What is your name?\n";
cin >> user.name;
cout << "Thank you "<<user.name<<". Please choose a class:\n\n";
cout << "Please Choose Your Class Type:\n"
"1] Thief\n"
"2] Cleric\n"
"3] Mage\n"
"4] Warrior\n";
cin >> user.proftype;
while(user.proftype < 1 || user.proftype > 4) // <-- error line
{
//uses switch statments which are not posted in code here
}
}

I am just wondering if someone knows the answer to this. I have tried for 2 days trying to fix it. Or if anyone knows of a better way of doing this.

red_baron
07-15-2002, 04:57 PM
user.proftype == 0;

isn't it suppose to be 1 equal cause 2 equals is comparing and 1 is assigning a value, but thats the only mistake i see in your code.

Quantrizi
07-15-2002, 05:00 PM
Nope, if I do that, I get this error:

C:\Program Files\Microsoft Visual Studio\My Projects\RPG\main.cpp(42) : error C2593: 'operator =' is ambiguous
C:\Program Files\Microsoft Visual Studio\My Projects\RPG\main.cpp(54) : error C2679: binary '<' : no operator defined which takes a right-hand operand of type 'const int' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio\RPG\main.cpp(54) : error C2679: binary '>' : no operator defined which takes a right-hand operand of type 'const int' (or there is no acceptable conversion)

The Dog
07-15-2002, 05:09 PM
Of what type is user.proftype
Is it an int or another class type?

Quantrizi
07-15-2002, 05:11 PM
it's of a struct....here's the struct for it:

struct PLAYER
{
apstring name;
apstring proftype;
};
PLAYER user;

*I have apstring.h included

The Dog
07-15-2002, 05:21 PM
Now hear dis

I'm not sure 'bout apstring, but if it's a class then then problem
is that the '=' operator was not overloaded to accept an int.

Try making proftype an int rather than an apstring:

struct PLAYER
{
apstring name;
int proftype;
};
PLAYER user;

void begin()
{
user.proftype = 0;
system("cls");
pcol();
cout << "What is your name?\n";
cin >> user.name;
cout << "Thank you "<<user.name<<". Please choose a class:\n\n";
cout << "Please Choose Your Class Type:\n"
"1] Thief\n"
"2] Cleric\n"
"3] Mage\n"
"4] Warrior\n";
cin >> user.proftype;
while(user.proftype < 1 && user.proftype > 4) // <-- error line
}

Quantrizi
07-15-2002, 05:25 PM
that one screws up my loading and saving functions.....

The Dog
07-15-2002, 05:31 PM
Well then look up the methods of apstring if it is a class.
There should be one that returns the string/buffer. Try assigning
to the returned pointer.

OR

Lookup how the '=' operator is overloaded and what it accepts.

If it can accepet char* then you do this:

user.proftype = "";

and if the [] operator was overloaded too, then you should do this

while(user.proftype[0] < 1 && user.proftype[0] > 4)

Quantrizi
07-15-2002, 05:38 PM
Originally posted by The Dog
Well then look up the methods of apstring if it is a class.
There should be one that returns the string/buffer. Try assigning
to the returned pointer.

This was already done yesterday, but no info.

If it can accepet char* then you do this:

user.proftype = "";

and if the [] operator was overloaded too, then you should do this

while(user.proftype[0] < 1 && user.proftype[0] > 4)

The fist one (user.proftype ="";...never thought of that one, thanks....the second one I'll try first...thank you

TechWins
07-15-2002, 11:01 PM
you might have to declare the struct as



external struct PLAYER
{
apstring name;
int proftype;
} user;

//forget about doing PLAYER user...that's a waste of time



Basically if the struct is declared in .h file and is going to be used in another file I think you might have to delcare the file as an external struct. I'm not positive, though, and I'm probably wrong because I only skimmed over the thread.:)

Quantrizi
07-16-2002, 05:48 AM
TechWins: You ain't wrong, but I did fix it. I had to take out the while, and the counter (user.proftype == 0). But thanks anyways.