Reputation: 26157
The test-case code it pretty self-explanatory. So basically, is something like this possible to do without the use of .cpp
files?
class A
{
public:
static int i;
static void test(void)
{
std::cout << "B::i = " << B::i << std::endl;
}
};
class B
{
public:
static int i;
static void test(void)
{
std::cout << "A::i = " << A::i << std::endl;
}
};
int A::i = 1;
int B::i = 2;
int main(int argc, char **argv)
{
A::test();
B::test();
return 0;
}
Upvotes: 0
Views: 100
Reputation: 23058
Define A::test()
and B::test()
outside.
class A
{
public:
static int i;
static void test(void);
};
class B
{
public:
static int i;
static void test(void);
};
int A::i = 1;
int B::i = 2;
void A::test(void)
{
std::cout << "B::i = " << B::i << std::endl;
}
void B::test(void)
{
std::cout << "A::i = " << A::i << std::endl;
}
Upvotes: 5