So, in the course of a simulation of a neural network I have two classes: neurons and synapses (which are basically the coupling between neurons).

Synapses mediate information between neurons, so a neuron has to be able to speak to a synapse, and that synapse has to be able to speak to other neurons. To me, that means a neuron has to contain a pointer to a synapse, and a synapse has to contain a pointer to a neuron.

How do I do that? Just writing

class a
{
b* bpointer;
};

class b
{
a* apointer
};

will lead to an error because b is not defined when the compiler gets to a. is the solution to make both classes derivations of a third, very abstract class? except for this detail, neurons and synapses have nothing in common.

Recommended Answers

All 4 Replies

is this the time for a dynamic cast?

Maybe something like this will work?

class a;
class b;

class a
{
b* bpointer;
};

class b
{
a* apointer
};
commented: friendly and helpful +1

it seems to work. thanks =)

It looks like Intrade has already covered it, but what you need/he suggested is called a "forward declaration". It's the same concept as a function prototype.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.