Sign in to follow this  
claesson92

[C++] Namespace problem

Recommended Posts

claesson92    459
Hi, i have a few classes in namespaces. They worked earlier, but now after i wrote some more code, they can't find each other. Here is all code: http://code.google.com/p/cgdk/source/browse/#svn/trunk/CGDKFramework The important files for this problem is _stdlibrary.hpp, Vector.hpp & Vector2.hpp Here is all errors i get:
Error	1	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	2	error C2504: 'Vector' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	3	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	4	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	5	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	6	error C2143: syntax error : missing ')' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	7	error C2143: syntax error : missing ';' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	8	error C2059: syntax error : ')'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	9	error C2238: unexpected token(s) preceding ';'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	10	error C2327: 'CGDK::core::Vector2<T>::Vector' : is not a type name, static, or enumerator	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	11	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	12	error C2061: syntax error : identifier 'Vector'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	13	error C2995: 'CGDK::core::Vector2<T>::Vector2(void)' : function template has already been defined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	91	
Error	14	error C2039: 'Collection' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	15	error C2504: 'Collection' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	16	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	17	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	18	error C2504: 'Vector' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	19	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	20	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	21	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	22	error C2143: syntax error : missing ')' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	23	error C2143: syntax error : missing ';' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	24	error C2059: syntax error : ')'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	25	error C2238: unexpected token(s) preceding ';'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	26	error C2327: 'CGDK::core::Vector2<T>::Vector' : is not a type name, static, or enumerator	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	27	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	28	error C2061: syntax error : identifier 'Vector'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	29	error C2995: 'CGDK::core::Vector2<T>::Vector2(void)' : function template has already been defined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	91	
Error	30	error C2039: 'Collection' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	31	error C2504: 'Collection' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	32	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	33	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	34	error C2504: 'Vector' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	35	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	36	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	37	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	38	error C2143: syntax error : missing ')' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	39	error C2143: syntax error : missing ';' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	40	error C2059: syntax error : ')'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	41	error C2238: unexpected token(s) preceding ';'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	42	error C2327: 'CGDK::core::Vector2<T>::Vector' : is not a type name, static, or enumerator	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	43	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	44	error C2061: syntax error : identifier 'Vector'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	45	error C2995: 'CGDK::core::Vector2<T>::Vector2(void)' : function template has already been defined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	91	
Error	46	error C2039: 'Collection' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	47	error C2504: 'Collection' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	48	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	49	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	50	error C2504: 'Vector' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	51	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	52	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	53	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	54	error C2143: syntax error : missing ')' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	55	error C2143: syntax error : missing ';' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	56	error C2059: syntax error : ')'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	57	error C2238: unexpected token(s) preceding ';'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	58	error C2327: 'CGDK::core::Vector2<T>::Vector' : is not a type name, static, or enumerator	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	59	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	60	error C2061: syntax error : identifier 'Vector'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	61	error C2995: 'CGDK::core::Vector2<T>::Vector2(void)' : function template has already been defined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	91	
Error	62	error C2039: 'Collection' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	63	error C2504: 'Collection' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	64	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	65	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	66	error C2504: 'Vector' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	67	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	68	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	69	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	70	error C2143: syntax error : missing ')' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	71	error C2143: syntax error : missing ';' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	72	error C2059: syntax error : ')'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	73	error C2238: unexpected token(s) preceding ';'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	74	error C2327: 'CGDK::core::Vector2<T>::Vector' : is not a type name, static, or enumerator	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	75	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	76	error C2061: syntax error : identifier 'Vector'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	77	error C2995: 'CGDK::core::Vector2<T>::Vector2(void)' : function template has already been defined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	91	
Error	78	error C2039: 'Collection' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	79	error C2504: 'Collection' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	80	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	81	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	82	error C2504: 'Vector' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	83	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	84	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	85	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	86	error C2143: syntax error : missing ')' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	87	error C2143: syntax error : missing ';' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	88	error C2059: syntax error : ')'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	89	error C2238: unexpected token(s) preceding ';'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	90	error C2327: 'CGDK::core::Vector2<T>::Vector' : is not a type name, static, or enumerator	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	91	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	92	error C2061: syntax error : identifier 'Vector'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	93	error C2995: 'CGDK::core::Vector2<T>::Vector2(void)' : function template has already been defined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	91	
Error	94	error C2039: 'Collection' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	95	error C2504: 'Collection' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	96	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	




Share this post


Link to post
Share on other sites
claesson92    459
Quote:
Original post by Dragonsoulj
I'm not entirely sure, but it looks like it cannot find the libraries you are using. I get similar errors when I either don't include the right files or it cannot find the files.


_stdlibrary.hpp which all files includes, contains include statements for both Vector.hpp and Vector2.hpp. So they should find each other afaik..

Share this post


Link to post
Share on other sites
Did you add some #using statements or change some namespaces? This can happen if you have objects in different namespace with same name.

But my guess is you accidentally cut the end brace off of a namespace somewhere. Happens to me once in a while if I hack on lots of files at once and looks exactly like this.

Share this post


Link to post
Share on other sites
mattd    1078
Consider #includeing _stdlibrary.hpp. Eventually this #includes Log.hpp, which #pragma onces and in turn #includes _stdlibrary.hpp again. This time we pass over Log.hpp as it has a #pragma once directive processed for it. We #include Exception.hpp instead, and similarly to Log.hpp, it #pragma onces and #includes _stdlibrary.hpp again. We skip over Log.hpp and Exception.hpp, and #include MemoryObject.hpp.

This sort of thing continues through MemoryPointer.hpp, Collection.hpp, Vector.hpp, and finally Vector2.hpp. Since when Vector2.hpp #includes _stdlibrary.hpp all the other headers have been #include'd once, compilation moves out of _stdlibrary.hpp, back into Vector2.hpp proper, which it then attempts to compile. Of course, CGDK::core::Vector<T> has not been defined yet.

In effect, the headers at the bottom of _stdlibrary.hpp are being #included in reverse order!

To see that this is indeed the case, change the #include order at the bottom of _stdlibrary.hpp to:

//Exceptions, asserts
#include "Log.hpp"
#include "Exception.hpp"

//For classes
#include "MemoryObject.hpp"
#include "MemoryPointer.hpp"

//Vectors
#include "Vector2.hpp"
#include "Vector.hpp"

//Dynamic memory
#include "Collection.hpp"


Your code then compiles cleanly. (Note that this is NOT a long term solution! :])

You need to stop using one header as a "catch-all" that includes every single other header, and put a little more thought into the headers that each header really needs to include.

(As an aside, your SVN repo is missing your MSVC project file.)

[Edited by - mattd on February 16, 2010 5:13:06 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this