草庐IT

TEMPLATE_DEBUG

全部标签

C++ : friend declaration ‘declares a non-template function

我在重载时遇到问题流运算符(operator),我找不到解决方案:templateclassNVector{inlinefriendstd::ostream&operator&rhs);};templateinlinestd::ostream&NVector::operator&rhs){/*SOMETHING*/returnlhs;};它产生以下错误信息:warning:frienddeclaration‘std::ostream&operatorerror:‘std::ostream&NVector::operator如何解决这个问题?非常感谢。 最佳答

c++ - 错误 : expected primary-expression before ‘>’ : templated function that try to uses a template method of the class for which is templated

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭8年前。在使用模板和仿函数(未出现在这个问题中)时,我最终遇到了以下简化的问题。以下代码(也可用here)classA{public:templateboolisGood(intin)const{constTf;returninbooltryEvaluator(T&evaluator,intvalue){returnevaluator.isGood(value);}intmain(intargc,constchar*argv[]

C++ 如何使 template<T>f() 为整数 T 返回 -1,为指针类型返回 nullptr

我需要完成以下任务:templatef(){:return{-1ifTisofintegraltype,elsenullptr}}在我的特定用例中,T可以是四种类型之一:intPy_ssize_t//ssize_tPy_hash_t//ssize_tPyObject*//PyObjectissomeCstruct这是我迄今为止最好的解决方案:templateTtest(typenameenable_if::value,void*>::type=nullptr){return-1;}templateTtest(typenameenable_if::value,void*>::type=n

【正点原子STM32】STM32初体验(Keil MDK工具下载使用、DAP仿真器、MDK上配置DAP、Debug)

一、MDK5编译例程二、串口下载程序2.1、串口下载程序须知2.2、串口下载硬件连接2.3、配置下载工具(ATK-XISP.exe)2.4、STM32启动模式(M3和M4)三、DAP下载程序3.1、DAP下载硬件连接3.2、在MDK上配置DAP不同开发板的下载算法有所不同Build构建F7、Download下载F8四、DAP调试程序4.1、JTAG/SWD调试原理概述4.2、在MDK配置DAP仿真调试4.3、基础执行控制按钮介绍断点复位、执行控制查看程序段/函数执行时间结束仿真报错解决方法4.4、工具栏常用窗口按钮介绍CallStack窗口(调用栈窗口):查看函数调用关系&局部变量Watch窗

c++ - 哪些因素使迭代器在 Debug模式下如此缓慢(VC++ 2012)

我有一个包含10000个随机数(mod100)的vector,我想计算其中两个数字之和为100的对数。我写了以下内容:autonoPairsSumTo100=0;constautoitEnd=end(myNums);for(autoit1=begin(myNums);it1!=itEnd;++it1){for(autoit2=it1;it2!=itEnd;++it2){if(*it1+*it2==100){noPairsSumTo100++;}}}在我的机器上,这需要大约21.6秒才能在Debug模式下运行。如果我设置_ITERATOR_DEBUG_LEVEL=0(将_SECURE_S

c++ - 启用 _GLIBCXX_DEBUG 后,Stringstream 无法使用 double

我正在使用_GLIBCXX_DEBUG模式来帮助查找我的代码中的错误,但我遇到了一个问题,我认为这是库中的一个错误,但希望有人能告诉我我只是做错了什么。这是一个重现问题的简短示例:#define_GLIBCXX_DEBUG#include#includeintmain(intargc,constchar*argv[]){std::ostringstreamostr;ostr如果我注释掉#define,那么输出是(如预期的那样):Result:1.2有了_GLIBCXX_DEBUG定义,但是输出很简单:Result:我已经追踪到流的_M_num_put字段被保留为NULL,这导致在流中抛

c++ - 嵌套命名空间 : where should default template arguments go? 中模板类的前向声明

我在嵌套命名空间中有一个模板类的前向声明namespacen1{namespacen2{templatestructA;}usingn2::A;}接着是一个定义,实际上它在不同的文件中,中间有一些东西:structX{};namespacen1{namespacen2{templatestructA{};}usingn2::A;}那么以下总是可以的:n1::n2::Aa;但是这个捷径n1::Aa;在clang中给出编译错误error:toofewtemplateargumentsforclasstemplate'A'除非我删除前向声明;g++两者都接受。clang似乎保留在第一个不包含

c++ - g++ 错误 : specialization after instantiation (template class as friend)

考虑以下C++代码:templateclassSingleton{};classConcreteSingleton:publicSingleton{templatefriendclassSingleton;};intmain(){}Singleton应该是ConcreteSingleton的friend:它适用于Microsoft的可视化C++编译器。但是,我不能用g++4.8.4编译它。错误是:error:specializationof‘Singleton’afterinstantiationtemplatefriendclassSingleton;有什么办法可以解决吗?

c++ - NDEBUG 和 _DEBUG 在 Visual Studio 2015 中定义在哪里?

我可以转到默认VisualStudio2010项目的设置,并查看在“配置属性”>>“C/C++”>>中定义的NDEBUG或_DEBUG“预处理器”的“预处理器定义”:如果我转到默认VisualStudio2015项目的设置,“预处理器定义”是空的!我什至没有在VisualStudio2015.vcxproj中看到NDEBUG或_DEBUG。我知道它的定义是正确的,因为assert(false)只在调试配置中触发。Microsoft将这些定义隐藏在VisualStudio2015的什么地方?我可以修改它们吗,还是已经被我拿走了?编辑:Niall'sanswer是正确的。我不明白的是,如果

C++ template-id 不匹配任何模板?

我用模板和特化写了一个简单的代码:#includetemplateintHelloFunction(constT&a){std::coutintHelloFunction(constchar*&a){std::cout我认为char*特化是正确的,但是g++报告:D:\work\test\HelloCpp\main.cpp:11:5:error:template-id'HelloFunction'for'intHelloFunction(constchar*&)'doesnotmatchanytemplatedeclaration请帮我找出错误。 最佳答案