Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i am defining a struct data type using vs2010
for example

C++
//b.h head file
#include "a.h"
typedef struct myStruct
{

testStruct * m; //missing ';' before '*'


};


while teststruct is a struct defined in a.h file

the problem is I got missing ';' before '*' error but if i put the testStruct directly in the b.h file it works.
Can anyone figure out why .thanks..
Posted
Updated 22-May-13 18:15pm
v2
Comments
Sergey Alexandrovich Kryukov 22-May-13 23:55pm    
And what's in b.h now?..
—SA
Prasaad SJ 23-May-13 0:01am    
Did you specify struct before testStruct?
iDebD 23-May-13 2:49am    
you wrong....this is not happening in VS2010
CPallini 23-May-13 3:27am    
You should post a.h code too.
As side note, your typedef syntax looks incorrect (synonim is missing, see http://msdn.microsoft.com/en-us/library/05w82thz(v=vs.80).aspx )
Richard MacCutchan 23-May-13 3:29am    
Well spotted, you are indeed correct.

You swapped the arguments of your typedef - it's typedef {{type}} {{typename}} , so your typedef should be
C++
typedef struct {
  ...
} myStruct; 

This didn't cause the error, but if the typedef for testStruct looks the same, the compiler didn't get it, and therefore didn't recognize that name as a type name.

P.S.: of course there is no need for a typedef in C++ in this case (or ANSI C for that matter): you can just write:
C++
struct myStruct {
  ...
};

and can then use it as you would a typedef:
C++
void foo() {
   myStruct s;
}
 
Share this answer
 
v2
Hi,

I think, that if testStruct is of type struct, as the name says, you shall probably write the keyword struct in front of it !
C++
//b.h head file
#include "a.h"
struct myStruct
{
struct testStruct * m; //missing ';' before '*' 
};

Hope this helps.

Best regards,
J.K.
 
Share this answer
 
v2
Comments
Stefan_Lang 23-May-13 4:59am    
Before Ansi C 99 this was necessary for some compilers, but it shouldn't be any longer.

Based on the fact the typedef here is incomplete I suspect the same is true for the struct definition in a.h - see my solution.
I would suggest going by the standard MS Way
C#
#include "a.h"
typedef struct tagMyStruct
{

struct testStruct * m;


}ST_MYSTRUCT, *PST_MYSSTRUCT;
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900