草庐IT

non-main

全部标签

c++ - 为什么我收到错误 "non-template ' f' used as template”

我正在尝试了解在哪里使用template和typename我遇到了一个我无法完全解决的问题。我有一个模板函数f它使用传递给它的类型(将是一个类)来调用模板成员函数.f.我想我使用typename在函数体中是正确的,但是,我不断收到以下错误:source.cpp:Infunction'voidf()':source.cpp:11:19:error:non-template'f'usedastemplatesource.cpp:11:19:note:use'typenameT::C::templatef'toindicatethatitisatemplatestructA{structC{

C++ 编译器错误 "cannot be thread-local because it has non-POD type”“

这个声明:___threadAa;生成此错误:cannotbethread-localbecauseithasnon-PODtypeA在哪里classA{public://functiondeclarationprivate://datamembers};我正在尝试使用命令ogsincludes&ogsmk在Linux上进行编译。我们有静态线程,即在我们的应用程序进入之前,我们知道线程的数量,因此目前的工作是通过声明A的数组来完成的,即Aa[Numberofthreads].我该如何解决这个问题? 最佳答案 假设您使用gcc,线程本

c++ - 使用 protected 非虚拟析构函数时抑制 delete-non-virtual-dtor 警告

我有一个纯抽象接口(interface)类和一个实现该接口(interface)的派生类。structFoo{virtualvoiddoStuff()=0;};structBar:Foo{voiddoStuff()override{}};我的接口(interface)类没有虚拟析构函数。因此,尝试使用基类指针破坏派生实例显然是未定义的行为intmain(){Foo*f=newBar;f->doStuff();deletef;}幸运的是我的编译器足够聪明,可以捕捉到这个(使用-Werror)main.cc:15:9:error:deletingobjectofabstractclasst

c++ - 静态内联变量是否需要在main之前初始化?

如果我有以下A.h文件(仅header):#pragmaoncestructA{staticinlinestructInitializer{Initializer(){std::cout#include"A.h"(来自另一个header,将包含在main.cpp中)是否足够,所以Initializer::Initializer()之前被调用main()?我读到标准要求仅在使用前使用动态初始化来初始化静态变量。Itisimplementation-definedwhetherornotthedynamicinitialization(8.5,9.4,12.1,12.6.1)ofanobj

c++ - 在静态库中调用 main 之前的函数

我有一个类型注册系统,用于自定义形式的运行时类型信息。到目前为止,我已经使用以下宏在main之前调用注册函数并注册类型:#defineREGISTRATION\staticvoid_register();\namespace{structtemp{temp(){_register();}};}\staticconsttempCAT(temp,__LINE__);\staticvoid_register()这样我就可以在许多不同的cpp文件中执行此操作:REGISTRATION(){RegisterNewType(vec2)->RegisterMember("x",&vec2::x)->

c++ - Boost::Test——Main() 的生成?

我对设置boost测试库有点困惑。这是我的代码:#include"stdafx.h"#defineBOOST_TEST_DYN_LINK#defineBOOST_TEST_MODULEpevUnitTest#includeBOOST_AUTO_TEST_CASE(TesterTest){BOOST_CHECK(true);}我的编译器生成非常有用的错误消息:1>MSVCRTD.lib(wcrtexe.obj):errorLNK2019:unresolvedexternalsymbol_wmainreferencedinfunction___tmainCRTStartup1>C:\Use

c++ - _wtoi 返回零 : input zero or non-numerical input?

_wtoi当不能转换输入,所以输入不是整数时,返回零。但同时输入可以为零。这是一种确定输入是否错误或为零的方法吗? 最佳答案 这是C++,您应该使用stringstream进行转换:#include#includeintmain(){usingnamespacestd;strings="1234";stringstreamss;ss>i;if(ss.fail()){throwsomeWeirdException;}coutboost的lexical_cast有一个更简洁、更简单的解决方案:#include//...std::stri

c++ - 如何解决 : undefined reference to `non-virtual thunk to ...`

我正在尝试弄清楚如何进一步解决此问题。我还想知道如何安装更新版本的ld(如果有意义的话)。所有涉及的包管理器都告诉我,我是最新的。代码在ubuntu12.04和12.10上使用g++(4.7.2)编译、链接和运行,但在FC17上编译失败并出现此错误。ArchiveServiceLib/debug-posix/libArchiveLib.a(NamedIflTiffCache.o):(.rodata._ZTV26UnlockingGenericFileHandle[_ZTV26UnlockingGenericFileHandle]+0x58):undefinedreferenceto`I

c++ - gdb backtrace 没有显示 main() 的完整堆栈跟踪

我正在使用Xalanlibrary.我的程序在Xalan调用中的某处崩溃。我希望看到从main()一直到崩溃点的完整堆栈跟踪。我正在使用以下命令行进行编译g++-oprogram.out-g-O0-lxalan-cmyprogram.out我正在使用“backtracefull”命令并获得以下输出#00xb79313b4inxalanc_1_11::XPath::findRoot(xalanc_1_11::XPathExecutionContext&,xalanc_1_11::XalanNode*,intconst*,int,xalanc_1_11::MutableNodeRefLis

c++ - 警告 : non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]

这个问题在这里已经有了答案:C++ArrayInitializersWarnings(2个答案)关闭8年前。我刚刚在我的机器上安装了最新版本的cygwin和eclipseluna。它工作正常,我能够运行我的项目。但是,当我构建它们时,我收到了我不明白的警告。例如,这是我从“c++Primer”一书的网站上获得的头文件“Sales_item.h”的警告:warning:defaultedanddeletedfunctionsonlyavailablewith-std=c++11or-std=gnu++11[enabledbydefault]Sales_item()=default;^..