jjzjj

same_params

全部标签

c++ - 为什么 (void)sizeof(param) 不是 "using"参数?

我有一个定义如下的宏:#defineUNREF_PARAM_1(a)do{\(void)sizeof(a);\}\while(0)去除编译器警告。在我正在处理的一个新项目中,VS2013突然再次提示未引用的形式参数。奇怪的是,如果我只使用(void)param,它确实有效。有没有人知道为什么它在与(void)sizeof(param)一起使用时不起作用? 最佳答案 因为在sizeof(param)中,param是所谓的未计算的操作数,因此未被odr使用-也就是说,不是在运行时需要。但是,(void)param确实构成了odr-use

c++ - 多重继承 : Different Address same address

我写了一个示例程序。如果我打印pa和pb的地址都是不同的。你能告诉我为什么会这样吗?#includeusingnamespacestd;classA{intx;};classB{inty;};classC:publicA,publicB{intz;};intmain(){Cc;A*pa;B*pb;pa=&c;pb=&c;cout 最佳答案 作为KerrekSB把它,pa和pb在您的示例中,实际上并不指向c,而是指向A和Bc的子对象.通过多重继承,来自基类的数据本质上是一个接一个地堆叠起来。基类型指针只是偏移到该基类的数据。正因为如此

c++ - 警告 C4114 : same type qualifier used more than once

在将VC++6.0开发的代码迁移到VisualStudio2008时,我在代码的下面一行中收到此警告。constintconstCImportContext::PACKETSIZE=4096;我知道如何修复指针staticconstintconst*PACKETSIZE;//C4114staticconstint*constPACKETSIZE;//Correct但我的问题是如何解决这个警告,如果它像下面的警告(没有指针),staticconstintconstPACKETSIZE; 最佳答案 指针有两种不同的const限定符是有意

具有预增量 : With or without parentheses is the same? 的 C++ 箭头运算符

类(class)问题:Watchtheparenthesesaroundtheargumentofthe++operator.Aretheyreallyneeded?Whatwillhappenwhenyouremovethem?最初只有一个cout表达式。我添加了另一个以查看差异,如下所示:#includeusingnamespacestd;classClass{public:Class(void){coutvalue=0;coutvalue)value)我的想法是在没有括号的情况下再次测试它,看看有什么不同:...coutvaluevalue两种情况下的结果是一样的。因此我得出结论

c++ - 加速 C++ : Can I write a program that sorts either a list or a vector using the same command?

我意识到std::sort函数需要使用随机访问迭代器,而列表具有双向迭代器。有一个关于此的问题:SortlistusingSTLsortfunction我正在努力回答AcceleratedC++书中的问题5-4以供家庭学习。5-4.Lookagainatthedriverfunctionsyouwroteinthepreviousexercise.Notethatitispossibletowriteadriverthatonlydiffersinthedeclarationofthetypeforthedatastructurethatholdstheinputfile.Ifyour

c++ - 如何根据 std::is_same 检查返回不同类型

这个问题在这里已经有了答案:usingstd::is_same,whymyfunctionstillcan'tworkfor2types(4个答案)关闭2年前。考虑以下代码:templateTfoo(){if(std::is_same::value)return5;if(std::is_same::value)returnstd::string("bar");throwstd::exception();}当用foo()调用时,它会抛出一个错误cannotconvert‘std::__cxx11::string{akastd::__cxx11::basic_string}’to‘int’

c++ - void(param); 的意义/用途是什么?在功能开始时?

我刚刚浏览了Yahoo'sTraficServer的源代码它是用C++编写的。在几乎所有方法中(来自模块之一),他们对函数接收的每个参数执行void(param)。(例如下面)谁能解释一下这是干什么用的?intsome_method_name(caddr_taddr,size_tlen,caddr_tend,intflags){(void)end;(void)addr;(void)len;(void)end;(void)flags;..........}附言:有关实际源代码,请参阅方法来自http://github.com/apache/trafficserver/blob/trunk

c++ - 模板类中的模板函数 is_same

为什么这段代码会产生错误的输出?//this-type.cpp#include#includeusingnamespacestd;templateclassA{public:A(){cout>::value{};intmain(){Bb;}输出:$g++-std=c++11this-type.cpp$./a.outfalseA到B中的“*this”的类型是A,不是吗? 最佳答案 *this是A类型的左值,因此decltype(*this)将给出引用类型A&。回想一下左值上的decltype给出了引用类型:cout>::value&>

c++ - 数组的地址 VS 指针到指针 : Not the same?

我在处理指针时遇到了一个问题。到目前为止,我知道当我们创建任何数据类型的数组时,数组的名称实际上是一个指向数组第一个索引的指针(可能是静态指针)。对吗?所以我想要实现的是创建另一个指针,它可以保存数组名称的地址(即指向另一个指针的指针,在我的例子中是数组名称)例如:charname[]="ABCD";//nameholdingtheaddressofname[0]char*ptr1=name;//Whenthisispossiblechar**ptr2=&name;//Whynotthis.Itgivemeerrorthatcannotconvertchar(*)[5]tochar**

c++ - 使用 std::is_same,为什么我的函数仍然不能用于 2 种类型

我正在尝试编写一个可以打印堆栈和队列的函数,我的代码如下templatevoidprint_container(Cont&cont){while(!cont.empty()){if(std::is_same>::value){autoelem=cont.top();std::coutstk;stk.push(1);stk.push(2);stk.push(3);queueq;q.push(1);q.push(2);q.push(3);std::cout但是这里不行,错误信息是:demo_typeof.cpp:35:30:error:nomembernamed'front'in'std: