【问题标题】:C++ in Visual Studio 2013 - <Class> is undefinedVisual Studio 2013 中的 C++ - <Class> 未定义
【发布时间】:2014-11-03 11:34:13
【问题描述】:

我对 C++/VS 非常陌生,可能会在我的项目的代码/配置中遗漏一些东西。 在我的解决方案中,我有 2 个项目:

  • 首先是我从https://bitbucket.org/ben_key/ntl下载的NTL,编译成静态库NTL.lib。
  • 一个“测试”项目,其中:(1) 我通过在 properties->C++->Additional Include Files 中指定头文件的目录来添加头文件,(2) 在 properties->Linker->Input->Additional依赖项我添加了“NTL.lib”(3)将 NTL.lib 文件复制到与“test”项目的主 cpp 文件相同的目录中。

我的 cpp 只包含:

#include <NTL/GF2X.h>
int main() {
    GF2X P;
    return 1;
}

构建给出了输出:

1>------ Build started: Project: test, Configuration: Release Win32 ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppBuild.targets(388,5): warning MSB8028: The intermediate directory (Release\) contains files shared from another project (ntl-test.vcxproj).  This can lead to incorrect clean and rebuild behavior.
1>  QuickTest.cpp
1>..\tests\QuickTest.cpp(43): warning C4101: 'n' : unreferenced local variable
1>D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(79): warning C4291: 'void *operator new(size_t,_ntl_vector_placement)' : no matching operator delete found; memory will not be freed if initialization throws an exception
1>          D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(36) : see declaration of 'operator new'
1>          D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(319) : see reference to function template instantiation 'void NTL::BlockConstruct<T>(T *,long)' being compiled
1>          with
1>          [
1>              T=NTL::zz_p
1>          ]
1>          D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(291) : while compiling class template member function 'void NTL::Vec<NTL::zz_p>::DoSetLength(long)'
1>          D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vector.h(115) : see reference to function template instantiation 'void NTL::Vec<NTL::zz_p>::DoSetLength(long)' being compiled
1>          D:\studies\Thesis\NTL-Ben-Key\Include\NTL/vec_lzz_p.h(14) : see reference to class template instantiation 'NTL::Vec<NTL::zz_p>' being compiled
1>  MyTest.cpp
1>MyTest.cpp(4): error C2065: 'GF2X' : undeclared identifier
1>MyTest.cpp(4): error C2146: syntax error : missing ';' before identifier 'P'
1>MyTest.cpp(4): error C2065: 'P' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

这真的是一件简单的事情,我没有弄清楚我错过了什么。

【问题讨论】:

  • 该标头以NTL_OPEN_NNS 开头,这是一个可能扩展为namespace NTL{ 左右的宏。因此你需要使用 NTL::GF2X;除此之外,可能会针对缺少操作员删除的警告提交错误报告。如果编译器诊断正确,可能会导致内存泄漏或更糟。

标签: c++ visual-c++ header-files


【解决方案1】:

来自 NTL/include/NTL/tools.h:

#define NTL_NAMESPACE NTL
#define NTL_OPEN_NNS namespace NTL_NAMESPACE {
#define NTL_CLOSE_NNS  }

因此,当预处理器遇到NTL_OPEN_NNS 时,就像包含文件GF2X.h 中的情况一样,它会将其扩展为namespace NTL,这意味着GF2X 类是在命名空间NTL 中声明的。为了使用它,您需要将其完全限定为NTL::GF2X 或使用using namespace NTL 讨论哪个看起来here 例如。 同样,在 GF2X.h 的末尾,在展开 NTL_CLOSE_NNS 后有一个右括号

【讨论】:

    猜你喜欢
    • 2015-12-23
    • 1970-01-01
    • 1970-01-01
    • 2014-01-16
    • 2014-10-26
    • 1970-01-01
    • 2016-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多