Skip to main content
gamedev.net
🔒 Locked

Problem on header linking

Started by wah_on_2 3 replies 200+ views
Original Post
wah_on_2
wah_on_2
Hi, I meet a problem on header file linking. I have a stdhdr.h header file and a class Test.cpp & Test.h //Test.h #include "stdhdr.h" class CTest { void print(Struct1 *st1); }; //stdhdr.h class CTest; typedef struct Struct1 { CTest *test1; }Struct1; It contains error when i compile, how can i fix it? Thx error C2236: unexpected ''class'' ''CTest''
wah_on_2
wah_on_2
After i add the #include "Test.h", it contains another error
error C2061: syntax error : identifier ''Struct1''

//Test.h
#ifndef Test_H
#define Test_H
#include "stdhdr.h"

class CTest
{
void print(Struct1 *st1);
};
#endif


//stdhdr.h
#ifndef stdhdr_H
#define stdhdr_H
#include "Test.h" //<----added here

typedef struct Struct1
{
CTest *test1;
}Struct1;

#endif

Evil Bill
Evil Bill
That code works fine for me. Are you sure you''re not missing a semi-colon somewhere? Like in a header that #include''d before stdhdr.h in your main source file?

Member of the Unban Mindwipe Society (UMWS)
wah_on_2
wah_on_2
Mm....the problem really occur in my project.

Um....what mean the meaning of the first and the second Struct1 in the struct? Why does it can occur 2 two? When will write this?
Thx

typedef struct Struct1
{
CTest *test1;
}Struct1;
Evil Bill
Evil Bill

typedef struct Struct1
{
CTest *test1;
}Struct1;

Is a legacy from C days, so you didn''t have to write struct Struct1 foo, you could just write Struct1 foo. With C++, theres no point, so you can just say:

struct Struct1
{
CTest *test1;
};



Member of the Unban Mindwipe Society (UMWS)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.