-1

I'm making a neural net in C++ and i have got a serious problem with headers include look at this code:

Neurone.cpp:

//NEURONE.CPP

#include "stdafx.h"
#include "Neurone.h"
#include <cmath>

using namespace std;

Neurone::Neurone(Layer* current,Layer* next)
{

}

Neurone.h:

//NEURONE.H

#ifndef _NEURONE_H
#define _NEURONE_H

#include <vector>
#include "Layer.h"

class Neurone
{

public:
    Neurone(Layer* current,Layer* next);    

private:

};

#endif

Layer.cpp:

// LAYER.CPP

#include "stdafx.h"
#include <vector>
#include "Layer.h"

using namespace std;

Layer::Layer(int nneurone,Layer &neighborarg)
{

}

Layer.h:

//LAYER.H

#ifndef _LAYER_H
#define _LAYER_H

#include <vector>
#include "Neurone.h"

class Layer
{

public:
    Layer(int nneurone,Layer &neighborarg);
    //ERROR :C2061 Layer:Syntax error :Bad identifier

private:
    //std::vector <Neurone*> NeuronesInLayer;
    Neurone ANeuron;
    //ERROR :C2146 Syntax error :wrong identifier

};

#endif

Main.cpp:

//MAIN.CPP

#include "Neurone.h"
//#include "Layer.h"

int main()
{
    return 0;
}

I use VC++2010 and i can't understand why my class Neurone is not recognized by the class Layer. Anyone could help me please ? Thanks,

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
Francois
  • 1
  • 2
  • possible duplicate of [cyclic dependency between header files](http://stackoverflow.com/questions/2089056/cyclic-dependency-between-header-files) – Emile Cormier Mar 09 '11 at 00:59
  • Practically the same question was asked 40 minutes ago! – Emile Cormier Mar 09 '11 at 01:00
  • This guy calls them "Circular", doubt his searches turned up "cyclic" – Erik Mar 09 '11 at 01:03
  • Please search before asking duplicate questions. Cyclical Dependencies and Forward Declarations: - http://stackoverflow.com/questions/5239943/c-cyclical-header-dependency - http://stackoverflow.com/questions/2089056/cyclic-dependency-between-header-files - http://stackoverflow.com/questions/5058363/c-error-line2-has-not-been-declared/5058627#5058627 – Tim Mar 09 '11 at 00:55

1 Answers1

3

Neurone.h should not include Layer.h, but rather forward declare Layer: class Layer;. See the links @Tim refers to.

Erik
  • 88,732
  • 13
  • 198
  • 189