Jump to content
  • Advertisement
Sign in to follow this  
Hangin10

function ptr using class currently being defined.

This topic is 4845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having problems getting two classes to get along. Basically each one needs the other in their headers. I am using #pragma once to avoid the natural redefinition errors, but that's not the problem (or at least I don't think it is). (The actual code is fairly large, I'm doing my own GUI library as a learning exercise.) The basic idea is:
#pragma once
#include "B.h"

typedef void (*FUNPTR)(B*);

class A
{
private: 
     FUNPTR p;
};
-------
#pragma once
#include "A.h"

class B
{
public:
    /* stuff */
    A an_a;
};
The error I get is "C2460: 'A::FUNPTR' : uses 'A' which is being defined." which doesn't make any sense. Can someone help me with this? Thanks in advance :)

Share this post


Link to post
Share on other sites
Advertisement
A doesn't need B.

#pragma once
class B;

typedef void (*FUNPTR)(B*);

class A
{
private:
FUNPTR p;
};


-------

#pragma once

#include "A.h"

class B
{
public:
/* stuff */
A an_a;
};

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!