Error 1 error C2039: 'x' : is not a member of "

I am getting this error when I try to return the x and y positions of the sub I have posted my class and the code used to call along with the full error message, thanks to all who look.

Quick bit of background, the ints will be used as the coordinates for a sprite.

class Submarine {

private:

      static int subPosX;
      static int subPosY;

      bool powerEmpty;
      int power;

      int distance;

public:

      int setdistance(int);

      void setX(int x)
      {
            subPosX = x;
      }
      void setY(int y)
      {
            subPosY;
      }
      int GetX()
      {
            return subPosX;
      }
      int GetY()
      {
            return subPosY;
      }

This is how I am calling the ints

      static int x;
      static int y;
      //Submarine
      Submarine Lead;
      Lead.setX(150);
      Lead.setY(300);

      x = Lead.GetX();
      y = Lead.GetY();

This is the full error
Error      1      error C2039: 'x' : is not a member of 'Submarine'      c:\users\krups\desktop\uni\sub_game\sub\csci2605cwk\mainscroller3.cpp      58

gras5hopperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Infinity08Commented:
One thing I noticed :

>>       void setY(int y)
>>       {
>>             subPosY;
>>       }

You're not setting subPosY here ;)

Regarding the error you're having : could you indicate which line that error refers to ? Could you also post the entire mainscroller3.cpp file ?
0
gras5hopperAuthor Commented:

Thanks missed that:)

The error is at line:
      static int x;
      static int y;
      //Submarine
      Submarine Lead;
      Lead.setX(150);
      Lead.setY(300);
      Lead.
//Lead.GetX = x;
      //Lead.GetY = y;
>>      x = Lead.GetX();
      y = Lead.GetY();
I get no error for y :\ not sure why?

This is a project that I am doing I am using SFML.

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include <sstream>
#include "Sub3.h"
using namespace std;

int main()
{


      //window dimensions
      unsigned int width=600;
      unsigned int height=480;
      
      //we need a timer to update things - get a clock
      sf::Clock clock;
      static float timeAccumulator=0.0;

      //load resources for the scroller - images and sounds (if you have any)      
      sf::Image backGround;
      if(!backGround.LoadFromFile("images/background.jpg")) std::cout<<"File not found background.jpg"<<std::endl;
      
      //Load sub
            sf::Image subSprite;      
      if(!subSprite.LoadFromFile("images/subpng.png")) std::cout<<"File not found rock.png"<<std::endl;

      //resouces loaded

      sf::Sprite backGndSprite(backGround);
      backGndSprite.Scale(0.75f,0.8f);
      static int x;
      static int y;
      //Submarine
      Submarine Lead;
      Lead.setX(150);
      Lead.setY(300);
      Lead.
      //Lead.GetX = x;
      //Lead.GetY = y;
      x = Lead.GetX();
      y = Lead.GetY();

// Sub
      sf::Sprite playerSub(subSprite,Vector2f(x,y),Vector2f(2,2),0,Color(255,255,255,255));



      // Create main window
    sf::RenderWindow App(sf::VideoMode(width, height), "Scroller Window");
      
    // Start the display loop
    while (App.IsOpened())
    {
            sf::Event Event;
        static int speed=1; //remembers its value through the loop
            //check inputs in the event queue
                         while (App.GetEvent(Event))
                        {
                              // Close window : exit
                              if (Event.Type == sf::Event::Closed)
                                    App.Close();
                              // Escape key : exit
                              if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                                    App.Close();
      
                              }
                              //Left arrow key :
                              if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Left))
                              {
                                    
                                    cout<<"the x val is "<<Lead.GetX();

                              }
      
                              //other events are ignored
                        }


                         //update the things that need updating in the game loop
                        //update speed
                         float f=clock.GetElapsedTime();
                         clock.Reset();
                         timeAccumulator+=f;
                         scr.update(f*speed);

                         

                         //draw the things you have to draw
                         App.Draw(backGndSprite);
                         App.Draw(scr);      
                          App.Draw(playerSub);


                  
        // Finally, display the rendered frame on screen
        App.Display();
    }

   
    return EXIT_SUCCESS;

}
0
Infinity08Commented:
>>       Lead.
>> //Lead.GetX = x;
>>       //Lead.GetY = y;
>> >>      x = Lead.GetX();

Do you notice the first line in the above quote ? It should not be there (likely it was left by earlier edits or so).
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

gras5hopperAuthor Commented:
thats an accident sorry...
after removing it I am getting these 3 errors
Error      4      error LNK2001: unresolved external symbol "private: static int Submarine::subPosX" (?subPosX@Submarine@@0HA)      mainScroller3.obj
Error      5      error LNK2001: unresolved external symbol "private: static int Submarine::subPosY" (?subPosY@Submarine@@0HA)      mainScroller3.obj
Error      6      fatal error LNK1120: 2 unresolved externals      C:\Users\Krups\Desktop\Uni\Sub_Game\Sub\\csci2605Cwkdebug.exe

:S I mean I've left somthing out of place before but now I am just confused...
0
Infinity08Commented:
Your code tries to call methods of the Submarine function called subPosX and subPosY. But there are no such methods. You have methods named setX, setY, GetX and GetY though - you probably meant to call some of those instead.
0
Infinity08Commented:
Scratch that. I just noticed that you declared the subPosX and subPosY members static :

>>       static int subPosX;
>>       static int subPosY;

That should probably not be the case. Just remove the static keywords there.
0
gras5hopperAuthor Commented:
"Your code tries to call methods of the Submarine function called subPosX and subPosY. But there are no such methods. You have methods named setX, setY, GetX and GetY though - you probably meant to call some of those instead."

Apologies I don't quite follow...

Also I removed the statics after I searched using the error code. at the moment is seems as if the functions are working as the submarine renders at 300,150. I need to set up a way to move them, which I presume ill use the setX and some key events?
0
Infinity08Commented:
>> Apologies I don't quite follow...

Ignore that - I didn't read the error message properly. The correct solution is explained in http:#30140157.


>> at the moment is seems as if the functions are working

Looks great. So, your issue is resolved then ?
0
gras5hopperAuthor Commented:
If you could help me with one more function and ask set 500 points for your reply I will award it, but I would like to ask one more question as you are very helpful and I'd rather not get messed up again, Thanks in advance.

I added the function setXY to the class and I want to use key events to change the x/y of the sub
*updated class*
class Submarine {

private:

       int subPosX;
       int subPosY;

      bool powerEmpty;
      int power;
      
      int distance;

public:

      int setdistance(int);

      void setX(int x)
      {
            subPosX = x;
      }
      void setY(int y)
      {
            subPosY = y;
      }
      int GetX()
      {
            return subPosX;
      }
      int GetY()
      {
            return subPosY;
      }
      void setXY(int, int)
      {
            subPosX;
            subPosY;
      }

and the keyevent:

                              if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Left))
                              {
                                    //playerSub.Move(-3.0,0);
                                    Lead.setXY(-50.0,0.0);
                                    cout<<"the x val is "<<Lead.GetX();
                                    cout<<"the y val is "<<Lead.GetY();
                                        }

however the subPosX and subPosY do not seem to change and the sprite does not move :S

Thanks again
0
Infinity08Commented:
>>       void setXY(int, int)
>>       {
>>             subPosX;
>>             subPosY;
>>       }

As before, you need to actually assign something to subPosX and subPosY. you'll also want to name the two parameters (x and y resp. eg.).


Note also that :

>>                                     Lead.setXY(-50.0,0.0);

-50.0 and 0.0 are double's, not ints.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gras5hopperAuthor Commented:
Really helpful guy
0
gras5hopperAuthor Commented:
still can't set x/y with Lead.setXY(50,0);
they are not staying the same every game loop i think:S
0
Infinity08Commented:
Well, every time the left key is pressed, you set the position to the same exact position.

What you probably meant to do, is subtract 50 from the x position. Something like :

        Lead.setX(Lead.GetX() - 50);

or better yet, create a separate method to implement moves, like you had in the commented line of code :

>>                                     //playerSub.Move(-3.0,0);
0
gras5hopperAuthor Commented:
Thats a good idea, thank yo uvery much for all your help. =]
0
Infinity08Commented:
No worries :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Computer Games

From novice to tech pro — start learning today.