草庐IT

fno-implicit-templates

全部标签

C++11 `using` 关键字 : specialize template alias of template parameter

我今天在使用using时遇到了问题C++11中的关键字.我决定现在使用另一种方法(在下面的示例中添加为注释)。你可以想到X作为矩阵,Y作为mixin,目的是访问X的转置矩阵类型在Y.而不是typedef学习X在X,我们采用另一种更强大的方法并定义Sibling本身带有两个模板参数的别名。templatestructX{usingLeft=A;usingRight=B;templateusingSibling=X;//usingReversed=X;//WhatIreallywantandusenow.:-)};templatestructY{usingLeft=typenameA::L

c++ - "missing template argument"是什么意思?

我对C++和这个站点还很陌生,所以肯定会出现错误。当我尝试编译我的代码时,我会收到类似error:missingtemplateargumentbefore'b'之类的错误。几个小时以来,我一直在世界各地寻找答案,结果把我带到了这里。我的任务是实现一个模板化的类Collection来存储一个集合使用数组的对象,沿与集合的当前大小。#include#include"collection.h"usingnamespacestd;vintmain(intargc,char*argv[]){collectionb;//#ifndefCOLLECTION_H#defineCOLLECTION_H

C++ OO设计: Inheritance of template parameter

我有一个以Base为基类的继承链。我希望能够编写一个继承Base和可能的另一个Base派生类的类模板。我可以使用虚拟继承,但我找到了另一种解决方案。我想知道它是否是常见的/可观的/合法的类设计:编写一个类模板,其中模板参数是它派生的类,即它必须是Base或Base派生类。在构造函数中,我可以使用静态断言来真正确保用户没有使用任何非法类作为模板参数。如果它有效,我将永远不会有虚拟继承问题......问题是,这样做是可以的。我在其他项目中从未见过它,所以我想在使用它之前先确定一下。编辑:为了确保我不会混淆你,这里有一些代码:classBase{};classDerived:publicBa

c++ - 标准是否认为模板类的非模板成员本身是 "templates"?

考虑以下代码:#includetemplatestructA{static_assert(!std::is_same_v);};templatestructB{voidfoo(){A{};}};intmain(){}它来自thisquestion在俄罗斯StackOverflow上,它会询问它是否有效。我试图引用这个:[temp.res]/8.18Thevalidityofatemplatemaybecheckedpriortoanyinstantiation.[ Note:Knowingwhichnamesaretypenamesallowsthesyntaxofeverytempl

c++ - C-回调函数模板 : explicitly instantiate template

前提我正在使用一个提供以下接口(interface)的C库(来自C++):voidregister_callback(void*f,void*data);voidinvoke_callback();问题现在,我需要将函数模板注册为回调,这给我带来了问题。考虑以下代码:templatevoidmy_callback(void*data){…}intmain(){intft=42;register_callback(reinterpret_cast(&my_callback),&ft);invoke_callback();}这给了我以下链接器错误(在OSX上使用g++(GCC)4.5.1但

c++ - static_cast 和 Implicit_cast 有什么区别?

什么是implicit_cast?我什么时候应该更喜欢implicit_cast而不是static_cast? 最佳答案 我正在复制我对answerthiscomment的评论在另一个地方。Youcandown-castwithstatic_cast.Notsowithimplicit_cast.static_castbasicallyallowsyoutodoanyimplicitconversion,andinadditionthereverseofanyimplicitconversion(uptosomelimits.you

c++ - 哪个编译器是对的?需要模板化返回类型之前的 'template'?

Thissnippet(取自thisquestion)使用g++编译得很好(如图所示),只要template在返回类型之前存在。相比之下,VC10不编译该代码并出现以下错误:errorC2244:'A::getAttr':unabletomatchfunctiondefinitiontoanexistingdeclaration如果我删除template,VC10很高兴,但g++会报错:error:non-template'AttributeType'usedastemplatenote:use'A::templateAttributeType'toindicatethatitisat

c++ - 警告 : overflow in implicit constant conversion

在下面的程序中,第5行确实按预期给出了溢出警告,但令人惊讶的是,第4行在GCC中没有给出任何警告:http://www.ideone.com/U0BXnintmain(){inti=256;charc1=i;//line4charc2=256;//line5return0;}我在想这两行都应该给出overflow警告。还是我缺少什么?我做这个实验的主题是:typedeftypechecking?在那里我说了以下内容(我从答案中删除了,因为当我运行它时,它并没有像我预期的那样显示)://However,you'llgetwarningforthiscase:typedefintT1;ty

c++ - 使 : implicit rule to link c++ project

我正在学习制作教程。我正在尝试构建的非常简单的测试项目只有3个文件:./src/main.cpp./src/implementation.cpp和./include/header.hpp这是制作文件。VPATH=srcincludeCPPFLAGS=-Iincludemain:main.oimplementation.omain.o:header.hppimplementation.o:header.hpp在不带任何参数的情况下调用ma​​ke仅构建目标文件,但不链接可执行文件。prog应该有一个隐含的规则,或者我错过了什么?我真的需要有人为我指明正确的方向。谢谢。我使第一个目标名称与

c++ - 这个 "if e is a pack, then get a template name, otherwise get a variable name"是否有效?

我尝试构建一个不需要typename或template的案例,但仍会根据给定名称t生成变量或模板是否为函数参数包templatestructA{templatestaticvoidf(int){}};templatestructA{staticconstintf=0;};templateusingtype=int;templatevoidf(Tt){A...)>::f(1);}intmain(){f(1);}以上将引用staticconstint,并进行比较。以下刚好有Tt变成了一个包并制作f引用模板,但GCC也不喜欢templatevoidf(T...t){A...)>::f(1);