CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2007
    Posts
    52

    Odd errors when including certian files

    Ok, I have this program with a few different files, but I'm going to focus on the ones that are in this problem.

    EventReciever.h/.c, LoadScreen.h/.c, CGUI.h/.c, and CommonInclude.h

    The header files are in the format
    Code:
    #ifndef <filename>_H
    #define <filename>_H
    // All the definitions of structures, classes, and functions
    #endif <filename>_H
    obviously just replace <filename> with COMMONINCLUDE or something else.

    Everything except LoadScreen includes CommonInclude.h

    EventReciver defines a structure ToDoOnEvent and a class EventReciver

    CGUI includes EventReciver.h and defines a class called CGUI

    LoadScreen includes CGUI.h and defines a class called FrameLoader derived from CGUI

    Now, like this there is no problem, however I want to add a pointer to a CGUI to the structure ToDoOnEvent, but when I include CGUI.h in EventReciver.h I get an error

    error C2143: syntax error: missing ';' before '*'
    error C4430: missing type specifier - int assumed. Note C++ do...
    error C4430: missing type specifier - int assumed. Note C++ do...

    all of these errors bring me to a line in CGUI.h in the class definition

    Code:
    class CGUI
    {
    public:
    //variables
    IrrlichtDevice* m_Device;
    EventReciver* m_EventReciver;  <-THIS IS THE LINE WHERE IT GIVES ME THE ERROR
    s32 m_ExitCode;
    //functions
    void Exit(s32 exitCode);
    //constructor
    //IrrlichtGUI();
    //destructor
    ~CGUI();
    };
    }
    NOTE: s32 is typedef as an int

    I'm a mediocre C++ programmer, and I'm stumped on this one.

    while I'm at it I might as well ask a few more generic C++ questions:
    1. How do you call a parent class destructor/constructor in the child class destructor/constructor? Is it done automatically?

    2. When you delete an array thats contents have been allocated with new will it free all the memory if you go: delete []array; delete array;?

    3. Is it possible to get a pointer to a function of a class and call that function with the pointer?

    Thanks for any help given.
    KTNXBYE

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Odd errors when including certian files

    It looks like you need a forward declaration in CGUI.h instead, e.g.,
    Code:
    class EventReciver;
    
    class CGUI
    {
    public:
        // ...
    1. How do you call a parent class destructor/constructor in the child class destructor/constructor? Is it done automatically?
    They are called automatically. However, you can use the initialisation list to invoke a particular base class constructor other than the default, e.g.,
    Code:
    class Base
    {
    public:
        Base(int x) : x_(x) {}
    private:
        int x_;
    };
    
    class Derived : public Base
    {
    public:
        Derived(int x) : Base(x) {}
    };
    2. When you delete an array thats contents have been allocated with new will it free all the memory if you go: delete []array; delete array;?
    You should match new[] with delete[], so delete is out of place here. The actual allocation/freeing of memory depends on the allocator, from what I understand, but generally the memory for the dynamically allocated array will be deallocated after a delete[].

    3. Is it possible to get a pointer to a function of a class and call that function with the pointer?
    Somewhat, with member function pointers, but these are not exactly normal function pointers.
    Last edited by laserlight; February 7th, 2008 at 01:45 AM.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

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