use of undefined type????

Discussion in 'C++' started by Anonymous Infidel - Aborted Islam with a hanger, Jun 6, 2007.

  1. I have two classes(class A, class main). class main uses a pointer to
    class A and class A uses a global pointer to main. My problem is I
    keep getting these errors: :(

    a.h(12) : error C2027: use of undefined type 'main'
    a.h(4) : see declaration of 'main'
    a.h(12) : error C2227: left of '->SomeDriver' must point to class/
    struct/union/generic type

    How do I fix this?

    Thx ahead of time.
    ********
    #include "main.h"
    #include "A.h"

    main *g_main = NULL;
    int _tmain(int argc, _TCHAR* argv[])
    {
    g_main = new main;
    g_main->a = new A;
    g_main->a->Print();
    g_main->a->SomeFunction();

    return 0;
    }
    *********
    #ifndef MAIN_H
    #define MAIN_H
    class A;
    class main
    {
    public:
    void SomeDriver()
    {
    printf ("driver called\n");
    }
    void PrintA()
    {
    a->Print();
    }
    A *a;
    };
    extern main *g_main;
    #endif
    *******
    #ifndef A_H
    #define A_H
    class main;
    class A
    {
    public:
    void SomeFunction()
    {
    g_main->SomeDriver();
    }
    void Print()
    {
    printf ("Characters: a\n");
    }
    };
    #endif
    Anonymous Infidel - Aborted Islam with a hanger, Jun 6, 2007
    #1
    1. Advertising

  2. Anonymous Infidel - Aborted Islam with a hanger

    Stefan Naewe Guest

    On 6/6/2007 3:59 PM, Anonymous Infidel - Aborted Islam with a hanger wrote:
    > I have two classes(class A, class main). class main uses a pointer to
    > class A and class A uses a global pointer to main. My problem is I
    > keep getting these errors: :(
    >
    > a.h(12) : error C2027: use of undefined type 'main'
    > a.h(4) : see declaration of 'main'
    > a.h(12) : error C2227: left of '->SomeDriver' must point to class/
    > struct/union/generic type
    >
    > How do I fix this?
    >
    > [code snipped] see one of his other posts.


    What's wrong with you?
    Do you read answers to your posts?

    S.
    --
    Stefan Naewe stefan dot naewe at atlas-elektronik dot com
    Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
    Plain text mails only, please http://www.expita.com/nomime.html
    Stefan Naewe, Jun 6, 2007
    #2
    1. Advertising

  3. Anonymous Infidel - Aborted Islam with a hanger wrote:
    > I have two classes(class A, class main). class main uses a pointer to
    > class A and class A uses a global pointer to main. My problem is I
    > keep getting these errors: :(
    >
    > a.h(12) : error C2027: use of undefined type 'main'
    > a.h(4) : see declaration of 'main'
    > a.h(12) : error C2227: left of '->SomeDriver' must point to class/
    > struct/union/generic type
    >
    > How do I fix this?


    First off, you should probably rename your class from 'main' to smth
    else. 'main' is the name of the function in your program that starts
    its execution.

    >
    > Thx ahead of time.
    > ********
    > #include "main.h"
    > #include "A.h"
    >
    > main *g_main = NULL;
    > int _tmain(int argc, _TCHAR* argv[])


    There is no standard function _tmain.

    > {
    > g_main = new main;
    > g_main->a = new A;
    > g_main->a->Print();
    > g_main->a->SomeFunction();
    >
    > return 0;
    > }
    > *********
    > #ifndef MAIN_H
    > #define MAIN_H
    > class A;
    > class main
    > {
    > public:
    > void SomeDriver()
    > {
    > printf ("driver called\n");
    > }
    > void PrintA()
    > {
    > a->Print();


    Class 'A' hasn't been defined here yet. Consider pulling this
    function out of the class definition into the translation unit.

    > }
    > A *a;
    > };
    > extern main *g_main;
    > #endif
    > *******
    > #ifndef A_H
    > #define A_H
    > class main;
    > class A
    > {
    > public:
    > void SomeFunction()
    > {
    > g_main->SomeDriver();


    Although your 'A.h' is supposedly included after your 'main.h',
    if it weren't, 'g_main' is undefined here. Consider pulling this
    function out of the class definition into a translation unit.

    > }
    > void Print()
    > {
    > printf ("Characters: a\n");
    > }
    > };
    > #endif


    Consider separating declarations and implementations of class
    member functions. It's always a good idea for beginners.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Jun 6, 2007
    #3
  4. On Jun 6, 7:08 am, Stefan Naewe <> wrote:
    > On 6/6/2007 3:59 PM, Anonymous Infidel - Aborted Islam with a hanger wrote:
    >
    > > I have two classes(class A, class main). class main uses a pointer to
    > > class A and class A uses a global pointer to main. My problem is I
    > > keep getting these errors: :(

    >
    > > a.h(12) : error C2027: use of undefined type 'main'
    > > a.h(4) : see declaration of 'main'
    > > a.h(12) : error C2227: left of '->SomeDriver' must point to class/
    > > struct/union/generic type

    >
    > > How do I fix this?

    >
    > > [code snipped] see one of his other posts.

    >
    > What's wrong with you?
    > Do you read answers to your posts?

    Yes.
    Anonymous Infidel - Aborted Islam with a hanger, Jun 6, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mantorok Redgormor
    Replies:
    70
    Views:
    1,731
    Dan Pop
    Feb 17, 2004
  2. Replies:
    2
    Views:
    6,693
    chhenning
    Jul 15, 2005
  3. Replies:
    8
    Views:
    545
  4. VK
    Replies:
    45
    Views:
    579
    Dr John Stockton
    Sep 12, 2006
  5. -Lost
    Replies:
    13
    Views:
    358
    Richard Cornford
    Jan 31, 2007
Loading...

Share This Page