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.

Edited 6 Years Ago by miturian: n/a

Maybe something like this will work?

class a;
class b;

class a
{
b* bpointer;
};

class b
{
a* apointer
};
Comments
friendly and helpful

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.

This question has already been answered. Start a new discussion instead.