c++ - 错误 : variable '*' has initializer but incomplete type and one other

标签 c++ class struct compiler-errors

我知道关于这个特定问题还有其他几个问题,但我找不到任何关于它的东西似乎有用,所以我发布了我的特定代码。

代码如下:

#ifndef __MEMORY_TRACKER_H__
#define __MEMORY_TRACKER_H__

#include <unordered_map>

namespace cige
{
namespace memory
{
class CIGE_API MemoryTracker
{
protected:
typedef struct AllocRecord
{
    size_t bytes;
    std::string filename;
    size_t line;
    std::string func;

    AllocRecord() :
        bytes(0), line(0)
    { }
    AllocRecord(size_t sz, const char* file, size_t ln, const char* fun) :
        bytes(sz), line(ln)
    {
        if (file)
            filename = file;
        if (fun)
            func = fun;
    }
} AllocRecord;

std::string m_leakFileName;
bool m_dumpToConsole;
typedef std::unordered_map<void*, AllocRecord> AllocMap;
AllocMap m_allocationMap;

size_t m_totalAllocations;
bool m_recordEnable;

protected:
void reportLeaks();

MemoryTracker() :
    m_leakFileName("CIGEMemory.log"), m_dumpToConsole(true), m_totalAllocations(0), m_recordEnable(true)
{ }

public:
void setReportFileName(const std::string& name)
{
    m_leakFileName = name;
}
const std::string& getReportFileName() const
{
    return m_leakFileName;
}
void setReportToConsoleOutput(bool b)
{
    m_dumpToConsole = b;
}
bool getReportToConsoleOutput() const
{
    return m_dumpToConsole;
}
void setRecordEnable(bool b)
{
    m_recordEnable = b;
}
bool getRecordEnable() const
{
    return m_recordEnable;
}

size_t getTotalMemoryAllocated() const
{
    return m_totalAllocations;
}

void _recordAlloc(void* ptr, size_t sz, const char* file = nullptr, size_t ln = 0, const char* fun = nullptr);
void _recordDealloc(void* ptr);

~MemoryTracker()
{
    reportLeaks();
}

static MemoryTracker& get();
};
}
}

#endif // __MEMORY_TRACKER_H__

我得到:variable 'cige::memory::CIGE_API cige::memory::MemoryTracker' has initializer but incomplete type 在类声明的行。我查看了所有内容,但找不到解决此问题的任何答案。

我也有错误 expected '}' or ',' or ';'在“protected”之前 在带有 protected 的行中,就在结构的正上方。

如能对这两个错误中的任何一个提供帮助,我们将不胜感激。

编辑:CIGE_API 在一个单独的文件(包括在内)中定义为 __declspec(dllexport)

EDIT2:我解决了我的问题(见下面的答案)。它基本上只是 Code::Blocks 非常糟糕。

最佳答案

看起来 CIGE_API 没有定义。所以编译器尝试像变量声明 class Type Variable {initializer-list} 一样解析它,其中 TypeCIGE_APIVariableMemoryTracker

换句话说,从句法上讲,您是在预先声明 CIGE_API 类型并创建此类型的变量,而不是定义类。

关于c++ - 错误 : variable '*' has initializer but incomplete type and one other,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22620729/

相关文章:

c++ - 原始 float 和 double 支持多少位小数?

c++ - 将字符串参数传递给 fstream.open 时出错

c - 从节点打印值

c++ - 将 Struct 信息放入一个大数组中

c++ - 将 C++ union 结构转换为 VB6

c++ - 强制清理临时变量

c++ - 将其他参数作为默认值的函数参数

php - Laravel 5 扩展核心类

ruby - 按属性查找对象

c# - 根据另一个组合框 C# 的选择生成组合框列表(由数据库链接)