who can help me of this error?

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
 
H

Hendrik Schober

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])
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top