草庐IT

template_func

全部标签

c++ - "could not convert template argument"指针参数错误,即使使用强制转换

假设我有一个声明如下的模板类:templatestructy{int*b;y(){b=x;}}我确实需要模板参数是一个常量内存地址——它是一个嵌入式代码。如果我尝试像这样实例化它:(编译器是带有-std=gnu++11的gcc4.8.1)yc;我会收到错误消息“无法将模板参数‘1’转换为‘int*’”,这没关系,而且符合标准。我明白。我的问题是转换为指针也不起作用:yd;y(1)>e;error:couldnotconverttemplateargument'1u'to'int*'在这两种情况下。这是为什么?模板参数已经转换,不是吗? 最佳答案

c++ - `template` 关键字限定符能否使代码编译成功,但有所不同?

我正在阅读有关模板关键字限定符(https://www.ibm.com/support/knowledgecenter/SSPSQF_9.0.0/com.ibm.xlcpp111.aix.doc/language_ref/keyword_template_qualifier.html和WhereandwhydoIhavetoputthe"template"and"typename"keywords?)的信息,但仍有一些内容让我感到困惑。是否可能有这样的代码,它编译成功,但会导致两种不同的操作?SomeObjectInstance.templatesome_function();Some

WPF界面魔法:探秘Template奇妙世界,个性化定制你的UI

 概述:WPF中的Template机制为界面定制提供了强大工具,包括控件模板、ItemsPresenter、ItemsPanel、和ItemContainerStyle。通过这些功能,开发者能精确定义控件外观和布局,个性化每个项的样式,实现灵活而美观的用户界面。WPF中各种Template功能用途:Template(控件模板):用途: 控件模板用于定义整个控件的外观和布局。示例: 在ComboBox中,可以通过模板定义文本区域、下拉按钮区域以及Items的Popup区域。ItemsPresenter(项呈现器):用途: 在控件样式中标记一个区域,用于展示该控件的Items。示例: 在Combo

c++ - 标准 :forward inside a template class

templateclassBlockingQueue{std::queuecontainer_;templatevoidpush(U&&value){static_assert(std::is_same::type>::value,"Can'tcallpushwithoutthesameparameterastemplateparameter'sclass");container_.push(std::forward(value));}};我希望BlockingQueue::push方法能够处理T类型对象的右值和左值引用,以将其转发到std::queue::push正确的版本。是像上面

c++ - 从 z3 模型读取 z3 数组的 func interp

假设我在公式中有2个数组,我想使用z3检查其可满足性。如果z3返回sat,我想读取z3模型中的第一个数组,并将其打印为键、值对和默认值。稍后我想将其转换为map并对其进行进一步分析。这是我运行的示例:voidfind_model_example_arr(){std::cout0);s.add(select(some_array_2,5)我得到以下输出:find_model_example_involving_arraysat(define-funsome_array_1()(ArrayIntInt)(_as-arrayk!0))(define-funsome_array_2()(Arr

c++ - 错误 : ‘template<class> class std::auto_ptr’ is deprecated

我正在使用scons和ubuntu。当我使用'scons'制作一些程序时,会发生错误,例如,src/db/DBTextLoader.cc:296:3:error:‘templateclassstd::auto_ptr’isdeprecated[-Werror=deprecated-declarations]/usr/include/c++/5/bits/unique_ptr.h:49:28:note:declaredheretemplateclassauto_ptr;这是我的命令;$./configuer$sourcesomething.sh$scons其实我也不知道。我已经在搜索这个

c++ - 错误 : Expected template-name before '<' token

我正在尝试编译一个实现chain和chainNodes的程序并在以下行(第22行)出现错误:classchain:publiclinearList错误是:Error:expectedtemplate-namebefore'知道为什么会出现这种情况吗?我的代码如下://linkedimplementationofalinearlist//derivesfromabstractclasslinearListjusttomakesure//allmethodsoftheADTareimplemented#ifndefchain_#definechain_#include#include#in

c++ - C++ 中 (base->*&Func)() 的含义是什么

下面是简单的类定义classBase{public:virtualvoidFunc(){cout和声明(b->*&Base::Func)();调用Func的派生版本,与b->Base::Func()不同,它按预期调用基础版本,为什么会发生这种情况,调用的确切含义是什么? 最佳答案 调用的意思是增加冗长。基本上:表达式&Base::Func是指向成员函数的指针,并且(b->*x)()是调用成员函数的语法x指向b指向的对象。在这个情况下,因为x是一个常量,所以它与写作大致相同*&变量。与b->Func()含义相同。至于为什么它的行为不同

C++11 : Is it possible to give fixed-template-parameted template to varidic-template-template-parameter?

(是的,由于我糟糕的英语,标题很奇怪;我希望有人能改进它。)接听thisquestion,我发现这段代码有效:templateclassA{};templateclassU>classB{};intmain(){Bit_works;}..虽然templateclass和templateclass不相等。我试图弄清楚为什么这是可能的,并观察了N3337standard的[temp.param],但我找不到任何东西。怎么可能? 最佳答案 是的,这是可能的。C++1114.3.3/3特别允许,并提供了一个例子。3Atemplate-arg

c++ - 奇怪的 "Could not deduce template argument for ' T'"错误

错误在this代码://myutil.htemplateTConditionalInput(LPSTRinputMessage,LPSTRerrorMessage,predicatecondition);//myutil.cpptemplateTConditionalInput(LPSTRinputMessage,LPSTRerrorMessage,Predcondition){Tinputcout>input;while(!condition(input)){cout>input;}returninput;}...//c_main.cppintrow;row=ConditionalI