Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: simple private variable call problem  (Read 2328 times)

0 Members and 1 Guest are viewing this topic.

eradiuslore

  • Newbie
  • *
  • Posts: 2
    • View Profile
simple private variable call problem
« on: March 28, 2011, 07:59:51 pm »
hi im not sure if im just being a massive noob but im just trying to call a variable from my header and it just wont recognize it exists, what is it im doing stupidly wrong? and if possible could someone rearrange my code OR explain whats wrong. again bit of a noob.

game.h

Code: [Select]
#include <SFML/Graphics.hpp>


#pragma once


class game{

private:
sf::View view;

public:
game();
~game();
void initialise(sf::RenderWindow& App);
void update(sf::RenderWindow& App);
void render(sf::RenderWindow& App);
};


game.cpp

Code: [Select]
#include "game.h"

game::game(){}
game::~game(){}
void game::initialise(sf::RenderWindow& App){}

void game::update(sf::RenderWindow& App){

float Offset = 200.f * App.GetFrameTime();  
view.Move(0, -Offset);

}
void game::render(sf::RenderWindow& App){}

cristi121

  • Newbie
  • *
  • Posts: 33
    • View Profile
simple private variable call problem
« Reply #1 on: March 28, 2011, 08:04:18 pm »
If it's private, it can only be used by functions inside the class. Have you tried making it public?
If you want it to be private, you have to declare a function inside the class to do the operation. In you case:

Code: [Select]

class Game
{ void move_view( int x, int y)
   { view.Move(x,y);
   }
...
};

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
simple private variable call problem
« Reply #2 on: March 28, 2011, 09:33:48 pm »
He is accessing it from a member function of the class.

Can you give us the exact error message from the compiler?
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

devlin

  • Full Member
  • ***
  • Posts: 128
    • View Profile
simple private variable call problem
« Reply #3 on: March 29, 2011, 11:24:20 am »
In addition to what Groogy says - move your #pragma once to the top of the header-file.