2015-06-09 28 views
0

所以我正在做我的第一個「freestyle」項目在c + +。我很想嘗試建立一個基於opengl的引擎。我試圖創建一個可以存儲變量和結構的cpp ...這樣,代碼的所有其他部分都可以輕鬆地使用自定義結構和訪問並寫入變量(這是生命計數器會去的地方)。如何製作一個漂亮乾淨的變量存儲器?有問題通過過濾器獲取數據

但是我注意到,雖然它編譯...引擎不像我使用我的自定義Coord3D結構在一個.cpp,我已經放在過濾器(幷包括Variables.cpp)較低。

我怎樣才能得到這個,所以它工作正常?

櫃面圖像的arent工作....

Variables.cpp (located outside of the filters and folders) 
using namespace std; 
typedef float acc;//Defines the accuracy of the program 

#include "Dependencies\glew\glew.h" 
#include "Dependencies\freeglut\freeglut.h" 
#include <iostream> 

struct Config{ 
    bool Depth; 
}; 
struct Coord3D{ 
    acc x; 
    acc y; 
    acc z; 
}; 
struct Coord2D{ 
    acc x; 
    acc y; 
}; 

Shader_Loader.cpp (located inside of a folder/filter called "Core") 
#pragma once 
#include "../Variables.cpp" 

Coord3D it; 
it.x = 1; 
it.y = 1; 
it.z = 1; 
//THe debugger likes to put red underlines under the last 3 lines under "it" however the program compiles....? 
+3

Eww。 '#include「___。cpp」' – NathanOliver

+0

有一個頭文件來聲明'struct Coords3D;'並將它包含在需要使用的地方。 –

+0

@NathanOliver ...它有什麼問題嗎?我有../,所以我可以去一個過濾器和訪問最大的文件夾。沒有這個neccesary? – Andrew

回答

3

不能分配給成員這樣外部的函數體。你必須在一個函數中分配給它們。它看起來像這樣的功能

void myFunc() 
{ 
    it.x = 1; 
    it.y = 1; 
    it.z = 1; 
} 

或者,你可以使用統一的初始化。您Coord3D初始化改成這樣:

Coord3D it{ 1, 1, 1 }; 

在另一方面,不包括.cpp文件。在頭文件中聲明結構和函數聲明(.h文件),並將頭文件包含在代碼文件中。

相關問題