Skip to main content
gamedev.net
🔒 Locked

function ptr using class currently being defined.

Started by Hangin10 1 reply 500+ views
Original Post
Hangin10
Hangin10
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 :)
Fruny
Fruny
A doesn't need B.

#pragma once<font color=lime>class B;</font>typedef void (*FUNPTR)(B*);class A{private:      FUNPTR p;};


-------

#pragma once#include "A.h"class B{public:    /* stuff */    A an_a;};
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Hangin10
Hangin10
dangit! I could have sworn I tried that already...

Oh, well.. it works now. Thanks.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.