Hello, I have a problem using class in Visual C++, when I use the int health; from my class Ogre in main() I get the message Ogre::health is inaccessible :( and when I type a. in my main() and hover over it, it gives me a picture with the int health which has a big lock on it, pls help, how do I make my class unlocked?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include "stdafx.h"
#include <iostream>
class Ogre
{
int health;
};
int main()
{
Ogre a;
a.health;
return 0;
}
I don't know what you mean by locked, but your Ogre class lacks any access modifiers so it's members will default to private and therefore can't be accessed outside of the class, to make health public: