Jump to content

Friend Class, Forward Declarations


Recommended Posts

Hi

I have been trying to get the following to work

 

class TimerInterrupt: public Interrupts

{

public:

 

};

 

 

class Timer

{

 

public:

friend class TimerInterrupt; //A friend class

Timer(void);

int GetCount(void) { return Count;}

private:

 

class TimerInterrupt* InterruptPtr;

int Count;

 

};

 

 

Are friend classes supported? Also how are forward declarations declared?

 

// forward declarations

class Timer;

class UART;

class DUART;

 

The class declaration will attempt to construct the objects if this syntax is used, how do you work round this? or is it not supported?

 

Many thanks

Dave

Link to post
Share on other sites
  • 3 weeks later...

Hi Pavel

I have declared the Timer class at the top of the file like so

 

// forward declarations

class Timer;

 

class Interrupts

{

..................

}

class TimerInterrupt: public Interrupts

{

public:

TimerInterrupt(Timer* ownerptr){

InterruptOwnerPtr = ownerptr;

Reg(TIMER_INTERRUPT_NUMBER, this);

}

TimerInterrupt(int i){

 

}

virtual void ISR(int intNumber);

private:

class Timer* InterruptOwnerPtr;

 

};

 

class Timer

{

//friend class TimerInterrupt;

 

public:

Timer(void); //ERROR missing RIGHT BRACE

int GetCount(void) { return Count;}

private:

TimerInterrupt* InterruptPtr;

int Count;

};

 

and the above error at the Timer(void) constructor keeps appearing. If I get rid of the code that requires the forward timer declaration and the Timer forward declaration then it compiles okay

Many thanks

Dave

Link to post
Share on other sites
  • 1 month later...

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...