什么会阻止我创建类的非指针变量

What would stop me from creating a non pointer variable of my class?

本文关键字:指针 变量 阻止我 创建 什么      更新时间:2023-10-16

编辑::这似乎是Visual Studio 2013的一个bug。

由于某些超出我理解的原因,我不能创建类的非指针变量LineBuffer。我的代码中有许多类使用相同的格式,但它们都可以工作。我尝试更改名称,因为我认为可能类名称在其他地方被使用,但它仍然失败。我是不是错过了什么简单的东西?是否有打字错误,我无法找到在过去的2小时试图解决这个问题?这简直让我头疼。任何帮助这里将非常感激!

class TestClass
{
    LineBuffer lineBuffer;
    void LoadLine()
    {
        lineBuffer = LineBuffer();
    }
};

我得到的错误如下:

错误3错误LNK1120: 2个未解决的外部E: soreooth DevelopmentTestProjectsGraphicsDev-TestDebugGraphicsDev-Test.exe 11 GraphicsDev-Test

错误2错误LNK2019:未解析的外部符号"__declspec(dllimport) public: __thiscall LineBuffer::~LineBuffer(void)"(__imp_??1LineBuffer@@QAE@XZ)在函数__unwindfunclet$??0 testclass@@qae@xz 10美元E: SoreTooth 开发 TestProjects GraphicsDev-Test GraphicsDev-Test 主要。obj GraphicsDev-Test

错误1错误LNK2019:未解析的外部符号"__declspec(dllimport) public: __thiscall LineBuffer::LineBuffer(void)"(__imp_??0LineBuffer@@QAE@XZ)在函数"public: __thiscall TestClass::TestClass(void)"中引用(? ? 0 testclass@@qae@xz) E: SoreTooth 开发 TestProjects GraphicsDev-Test GraphicsDev-Test 主要。obj GraphicsDev-Test

LineBuffer.h类的代码:
#ifndef _LineBuffer_
#define _LineBuffer_
#include "GraphicsManagement_API.h"
class GraphicsManagement_API LineBuffer
{
public:
    LineBuffer();
    ~LineBuffer();
};
#endif
LineBuffer.cpp的代码:
#include "LineBuffer.h"
LineBuffer::LineBuffer()
{
}
LineBuffer::~LineBuffer()
{
}

我知道你会问,GraphicsManagement_API.h的代码:

#ifndef _GraphicsManagement_API_
#define _GraphicsManagement_API_
#include <d3d10.h>
#include <D3DX10.h>
#ifdef _GraphicsManagement_API_EXPORTS_
#define GraphicsManagement_API __declspec(dllexport) 
#else
#define GraphicsManagement_API __declspec(dllimport) 
#endif
#endif

但这恰好可以

class TestClass
{
    LineBuffer * lineBuffer;
    void LoadLine()
    {
        lineBuffer = new LineBuffer();
    }
};

如果您碰巧遇到这个问题,通过删除它们然后创建一个全新的文件来重新创建有问题的文件。在我的例子中,当我创建LineBuffer.cpp时,我意外地将其命名为LineBuffer。ccp显然这不会生成,并且Visual Studio不会将其识别为。cpp文件。我想我可以使用Visual Studio解决方案资源管理器重命名文件。显然,这并不像人们预期的那样起作用。我不得不删除整个文件并创建一个新文件。一旦我这样做了,它就成功构建了。我不确定这是Visual Studio 2013的bug还是设计。不管怎样,这都是适合我的解决方案。