[RESOLVED] weird warning?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] weird warning?

  1. #1
    Join Date
    Mar 2017
    Posts
    12

    [RESOLVED] weird warning?

    I get this warning:
    Name:  c++ issue.jpg
Views: 50
Size:  8.6 KB

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,724

    Re: weird warning?

    Quote 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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Mar 2017
    Posts
    12

    Re: weird warning?

    Quote Originally Posted by laserlight View Post
    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);
    };

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,719

    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. 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/

    C++17 Compiler: Microsoft VS2017 (15.3.4)

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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)