CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2005
    Location
    Canada
    Posts
    40

    Unhappy 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.

  2. #2
    Join Date
    Jan 2007
    Posts
    90

    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

  3. #3
    Join Date
    Nov 2005
    Location
    Canada
    Posts
    40

    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
  •  





Click Here to Expand Forum to Full Width

Featured