2017-08-27 194 views
-2

我想在C++中編寫一個神經網絡,並且在我試圖編寫的一個頭文件中,有一個包含頂部的問題。當我雙擊Eclipse的綱要中的包含文件時,它會將我帶到寫入文件中,所以Eclipse知道它在那裏,但編譯器不斷抱怨它不在。目錄看起來是這樣的(我切出無關的問題的所有文件):C++包含有趣的代碼Eclipse

src 
->Layers 
    -->Layer.h 
->Neurons 
    -->Neuron.h 
->main.cpp 

的Layers.h文件代碼如下:

#ifndef LAYERS_LAYER_H_ 
#define LAYERS_LAYER_H_ 
#include <vector> 
#include "../src/Neurons/Neuron.h" 

class Layer{ 
public: 
    std::vector<Neuron> layer; 
    Layer(Neuron a, int n){ 
     layer = std::vector<Neuron>(n); 
     for(int i = 0;i<n;i++){ 
      layer[i] = a; 
     } 
    } 
    virtual std::vector<double> fire(std::vector<double>); 
    virtual std::vector<double> fire(); 
    virtual std::vector<double> derivative(std::vector<double>); 
    virtual std::vector<double> derivative(); 
    virtual ~Layer(){} 
}; 



#endif /* LAYERS_LAYER_H_ */ 

,並與#線包括「../src/Neurons/Neuron.h」給出了錯誤

In file included from ..\src\Layers\Layer.cpp:7:0: 
..\src\Layers\Layer.h:11:10: fatal error: ../src/Neurons/Neuron.h: No such file or directory 
#include "../src/Neurons/Neuron.h" 
      ^~~~~~~~~~~~~~~~~~~~~~~~~ 
compilation terminated. 

我已經能夠以包括的main.cpp文件,它工作正常。

+0

應該是'../../ src/Neurons/Neurons.h'或'../ Neurons/Neuron.h'嗎?看起來你是通過一個目錄 –

回答

1

#include "../src/Neurons/Neuron.h"告訴編譯器在相對於當前文件位置的目錄層次結構中上升一級。因此../將已經在src之內,並且不需要添加/src。所以你的包括應該看起來像:

#include "../Neurons/Neuron.h" 
+0

這工作,我沒有意識到「../」移動了一個目錄。我認爲這是根目錄或類似的東西。謝謝。我會盡快接受你的回答。 – BadProgrammer99