How do I call a variable from one class to use it in another? The code is a bit off but basically im trying to take a variable from the class and use it in my main.
my.h
1 2 3 4 5 6 7 8 9 10 11 12 13
#ifndef MY_H
#define MY_H
#pragma once
class my
{
public:
my(void);
private:
staticint hp;
};
#endif
You have your function returning a 'void', you should be returning an integer. Also, a little thing: Why is your 'hp' variable static? And if you did want it to be static (for some reason), you should make your getHP and addHP functions static as well (considering all they are doing is accessing a static variable).
NT3 already explained that gethp needs to return an integer.
In my.h at line 9, you're attempting to return an integer, but the function is declared as void.
main.cpp line 11, the compiler is complaning because you're trying to print a void. There is no << operator that can print a void. Change gethp to return an int and this error will go away.