Click to See Complete Forum and Search --> : Odd errors when including certian files


BossOfTheGame
February 6th, 2008, 11:54 PM
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

#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


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.

laserlight
February 7th, 2008, 12:26 AM
It looks like you need a forward declaration in CGUI.h instead, e.g.,
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.,
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.