who can help me of this error?

  • Thread starter Thread starter Wonlay
  • Start date Start date
W

Wonlay

//file1.cpp
#include <stdio.h>

class A
{
public:
int i;
int j;
A ()
{
i = 1;
j = 2;
}
};

class B
{
public:
A a;
static void test ()
{
printf ("%d, %d", a.i, a.j);
}
};

void main ()
{
B::test ();
}
//error: the left of .i .j should be a struct/class/union.

//file2.cpp
#include <stdio.h>

class A
{
public:
int i;
int j;
A ()
{
i = 1;
j = 2;
}
};

class B
{
public:
static A a;
void test ()
{
printf ("%d, %d", a.i, a.j);
}
};

void main ()
{
B b;
b.test ();
}
//error link2001:
//fatal error link1120: 1

//file3.cpp
#include <stdio.h>

class A
{
public:
int i;
int j;
A ()
{
i = 1;
j = 2;
}
};

class B
{
public:
static A a;
static void test ()
{
printf ("%d, %d", a.i, a.j);
}
};

void main ()
{
B::test ();
}
//the same error with file2.cpp
 
Wonlay said:
//file1.cpp
[...]
class B
{
public:
A a;

non-static member
static void test ()

static member
{
printf ("%d, %d", a.i, a.j);

You cannot access non-static members within
static member functions, since those don't
have a 'this' pointer. ('a.i' is short for
'this->a.i'.)

Schobi

--
(e-mail address removed) is never read
I'm Schobi at suespammers org

"My hair style calls into immediate question all my judgements."
Scott Meyers
(http://www.google.de/[email protected])
 
Back
Top