C
Chris Portka
How can I modify static variables from outside the class they're
defined in? It doesn't work if I try to access them from a function,
from an instantiated object, or from the class itself. Here's an
example:
MAIN:
#include "test"
int main()
{
Test t;
//All of these give "unresolved external symbol"
t.x = 1;
t.setX(1);
Test::x = 1;
Test::setX(1);
}
TEST:
class Test
{
public:
static int x;
static void setX(int z) { x = z; }
};
defined in? It doesn't work if I try to access them from a function,
from an instantiated object, or from the class itself. Here's an
example:
MAIN:
#include "test"
int main()
{
Test t;
//All of these give "unresolved external symbol"
t.x = 1;
t.setX(1);
Test::x = 1;
Test::setX(1);
}
TEST:
class Test
{
public:
static int x;
static void setX(int z) { x = z; }
};