【问题标题】:Circular C++ Header includes [closed]循环 C++ 标头包括 [关闭]
【发布时间】:2011-07-11 13:02:47
【问题描述】:

我正在用 C++ 制作一个神经网络,但我遇到了一个严重的问题,包括头文件 看看这段代码:

神经元.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

图层.cpp:

// LAYER.CPP

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

using namespace std;

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

}

图层.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;
}

我使用 VC++2010,但我无法理解为什么类 Layer 无法识别我的类 Neurone。 任何人都可以帮助我吗? 谢谢,

【问题讨论】:

标签: c++ header cycle


【解决方案1】:

Neurone.h 不应包含 Layer.h,而是转发声明 Layer:class Layer;。请参阅@Tim 引用的链接。

【讨论】:

    猜你喜欢
    • 2012-08-11
    • 1970-01-01
    • 1970-01-01
    • 2022-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多