c++ - 循环 C++ header 包括

标签 c++ header cycle

<分区>

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

神经元.cpp:

//NEURONE.CPP

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

using namespace std;

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

}

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

主要.cpp:

//MAIN.CPP

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

int main()
{
    return 0;
}

我使用的是 VC++2010,但我不明白为什么我的 Neurone 类无法被 Layer 类识别。 有人可以帮我吗? 谢谢,

最佳答案

Neurone.h 不应包含 Layer.h,而是前向声明层:class Layer;。查看@Tim 引用的链接。

关于c++ - 循环 C++ header 包括,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5240188/

相关文章:

c++ - 刷新 boost::iostreams::zlib_compressor。如何获得 "sync flush"?

algorithm - 在图中查找长顶点不相交的循环

java - 使用 BFS 在有向图中查找循环?

c++ - 如何在 header 和 cpp 之间拆分静态/模板类?

c - 在 C 头文件 (.h) 中定义自引用结构?

java - 使用 Java 进行图形循环检测

c++ - Boost::Dijkstra 最短路径,如何从路径迭代器获取顶点索引?

c++ - 多个 .cpp 文件中包含的头文件

c++ - 当要访问的对象被多次封装时,如何正确使用setter?

css - CSS 页眉周围的空格