sprnova
asked on
Error 2501 with #include
I have a Binary tree header that compiles fine on its own but when I #include it on a form.h header I get loads of errors
error C2146: syntax error : missing ';' before identifier 'data'
missing storage-class or type specifiers
the tree header contains a
#ifndef BST_H
#define BST_H
does any one know the reason for this?
error C2146: syntax error : missing ';' before identifier 'data'
missing storage-class or type specifiers
the tree header contains a
#ifndef BST_H
#define BST_H
does any one know the reason for this?
It's a "header guard" TO stop the header being included multiple time, which would most likely result in the breech of the One Definition Rule (ODR). It is the same as the Visual Studio #pragma once.
Without more info it isn't really possible to answer this question. Try using the /E option on the compiler to get the preprocessed source file and then you might be able to see what's happening.
http://msdn2.microsoft.com/en-us/library/3xkfswhy(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/3xkfswhy(VS.80).aspx
ASKER
It is a regular form where #pragma once is already defined
ASKER
I meant is there any way to resolve these errors
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
are you allowed to include another header in a windows form header?
I see no reason why not. Ignoring the fact that it's Microsoft managed code, it's still C++ and (mostly) normal rules apply. I suspect the problem is more likely to be related to the content of the header. When you say the header compiles fine on its own, what do you mean? Headers don't get compiled, they get included into translation units. I presume you mean you have included it in a .cpp and that is what you have compiled? If you've never included it in anything it would never have been compiled. So, maybe the problem is the binary tree header itself and nothing to do with using it in the Windows form translation unit? Try including it in an empty .cpp file -- does it still build?