|
-
December 28th, 2009, 08:10 PM
#1
C2143, C2653; Weird class errors
Hey Codeguru, I've been having some weird problems on my code when compiling; it seems like my program isn't able to see the Item struct I created on either of my attempts I wrote below:
----------========------------
--------- ATTEMPT #1 ----------
----------========------------
ItemDictionary.h
-----
#pragma once
#include "Item.h"
struct ItemDictionary {
Item* operator[](unsigned int i); // <-- C2143: syntax error: missing ';' before '*' ; C4430: missing type specifier - int assumed
static Item* Get(unsigned int i); // <-- C2143, C4430
...
};
Item.h
------
#pragma once
struct Item {
...
};
----------========------------
--------- ATTEMPT #2 ----------
----------========------------
ItemDictionary.h
-----
#pragma once
#include "Item.h"
#include "Item.cpp" // NOTE: Included Item.cpp here
struct ItemDictionary {
...
};
Item.h
------
#pragma once
struct Item {
...
};
Item.cpp
------
#pragma once
#include "Item.h"
Item::Item( ... ) // <-- C2653: 'Item': is not a class or namespace name
{ // <-- C4430: missing type specifier - int assumed
this->appearance = appearance; // <-- C2673: 'Item': global functions do not have 'this' pointers
...
}
----------------------------
Does anybody know whats going on? Why is my Item class invisible right now? If you have any tips or suggestions, I'd really appreciate it =] Thanks.
-
December 28th, 2009, 11:37 PM
#2
Re: C2143, C2653; Weird class errors
hello,
this is called circular dependency. either break this by defining a new header. which both classes inherits or make one of them as forward declared.
regards
d
-
December 29th, 2009, 03:10 PM
#3
Re: C2143, C2653; Weird class errors
I'm not sure I understand..How would this be circular dependency if both Item.h and Item.cpp don't use ItemDictionary ? I tried it out anyways, and forward declared the Item class in ItemDictionary.h; but the only problem now is,
ItemDictionary.h
-----------
...
struct ItemDictionary {
...
static List<Item*> items;
};
List.h
-----------
template<class T>
struct List
{
...
T data; // <-- C2079: 'List<T>: ata' uses undefined struct 'Item'
};
Even if I forward declare the Item struct on the top of List.h, it still comes up with the same error.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|