2015-06-09 26 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文件),并将头文件包含在代码文件中。

相关问题