0

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 by miturian: n/a

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Fbody
1

Maybe something like this will work?

class a;
class b;

class a
{
b* bpointer;
};

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

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.