|
-
April 6th, 2017, 07:22 PM
#1
[RESOLVED] weird warning?
I get this warning:
c++ issue.jpg
MY CODE:
Code:
class PlayerClass{
public:
int ReturnName(){
return Name;
}
int ReturnLastName(){
return lastName;
}
int ReturnStamina(){
return Stamina;
}
int ReturnHealth(){
return Health;
}
int ReturnDistance(){
return StartdistancefromCamp;
}
int randVal(int min,int max){
return (rand() % (max - min + 1) + min);
}
private:
int const Name = randVal(0,1);
int const lastName = randVal(0,1);
int const Stamina = randVal(3,10);
int Health = randVal(50,100);
int StartdistancefromCamp=50,PlayerDecision;
int MobSelect = randVal(0,2);
};
I'm still kinda a beginner and I've seen this warning before in other programs, although it went away eventually.
Last edited by TheRedSpy; April 6th, 2017 at 10:38 PM.
-
April 6th, 2017, 08:15 PM
#2
Re: weird warning?
 Originally Posted by TheRedSpy
MY CODE:
I'm still kinda a beginner and I've seen this warning before in other programs, although it went away eventually.
That's a bad excuse for not posting the code corresponding to the error message. In this case it is easy enough to guess, but that is not always so, especially since people may not be familiar with your compiler and its specific wording of the error messages, whereas given the code they might be able to figure out the problem by viewing the code, or if not they could try to compile the code and see if the error messages from their compiler make more sense to them.
You probably tried doing something like this:
Code:
class X
{
// ...
int n = 0;
// ...
};
n is a non-static data member, and prior to C++11, initialising such data members within the class definition as above was not allowed.
-
April 6th, 2017, 10:38 PM
#3
Re: weird warning?
 Originally Posted by laserlight
That's a bad excuse for not posting the code corresponding to the error message. In this case it is easy enough to guess, but that is not always so, especially since people may not be familiar with your compiler and its specific wording of the error messages, whereas given the code they might be able to figure out the problem by viewing the code, or if not they could try to compile the code and see if the error messages from their compiler make more sense to them.
You probably tried doing something like this:
Code:
class X
{
// ...
int n = 0;
// ...
};
n is a non-static data member, and prior to C++11, initialising such data members within the class definition as above was not allowed.
sorry.. forgot to paste my code (I even put the [CODE], just didn't paste it in...)
heres my class:
Code:
class PlayerClass{
public:
int ReturnName(){
return Name;
}
int ReturnLastName(){
return lastName;
}
int ReturnStamina(){
return Stamina;
}
int ReturnHealth(){
return Health;
}
int ReturnDistance(){
return StartdistancefromCamp;
}
int randVal(int min,int max){
return (rand() % (max - min + 1) + min);
}
private:
int const Name = randVal(0,1);
int const lastName = randVal(0,1);
int const Stamina = randVal(3,10);
int Health = randVal(50,100);
int StartdistancefromCamp=50,PlayerDecision;
int MobSelect = randVal(0,2);
};
-
April 7th, 2017, 03:35 AM
#4
Re: weird warning?
The compiler warnings say what is the problem (c++11 feature used) and how to fix it by specifying the appropriate option to be used when invoking the compiler (to turn on c++11 features).
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|