草庐IT

Duck-typing

全部标签

c++ - MISRA C++ 2008 规则 5-2-7 直接或间接违反 : An object with pointer type shall not be converted to an unrelated pointer type,

在下面的例子中:voidbad_function(){char_t*ptr=0;//MISRAdoesn'tcomplainshere,itallowscastofchar*tovoid*pointervoid*p2=ptr;//thefollowing2MISRAviolationsarereportedineachofthecastsbellow(twopercodeline)//(1)Eventmisra_violation:[Required]MISRAC++-2008Rule5-2-7violation:Anobjectwithpointertypeshallnotbecon

C++ - 运算符重载错误 C4430 : missing type specifier - int assumed

我使用Borland5.5编译我的代码,没有弹出任何错误。但它无法正常运行,所以我决定使用VisualStudio2010来调试我的程序。VisualStudio给我这个错误:Error1errorC4430:missingtypespecifier-intassumed.Note:C++doesnotsupportdefault-intc:\users\johnny\documents\visualstudio2010\projects\stack_linkedlist\stack_linkedlist\classstack.cpp1111STACK_LinkedList它指向我的运

c++ - 解释错误: ISO C++ forbids declaration of `Personlist' with no type

我有一个类将处理我之前创建的另一个类的对象数组(工作正常)。当我尝试创建我的List类的对象时出现问题。这是列表类的标题:#ifndefpersonlistH#definepersonlistH#include"Person.h"#include#include#defineSIZE10namespacestd{classPersonList{private:Personpersons[SIZE];intarrnum;stringfilename;public:Personlist();};}#endif这是主要功能:#include#include"PersonList.h"usin

c++ - 抽象类 : invalid abstract return type for member function ‘virtual...’

在我的程序中我有这样的类层次结构:#include#include#includeusingnamespacestd;classaa;classbb;classroot{public:virtual~root(){}virtualrootadd(constaa&a)const=0;virtualrootadd(constbb&a)const=0;};classaa:publicroot{public:aa(){}aa(constaa&a){}virtualrootadd(constaa&a)const{returnroot(newaa());}virtualrootadd(constb

c++ - Visual Studio 2010 Arduino cpp 错误 : argument of type "char *" is incompatible with parameter of type "LPCWSTR"

我正在尝试设置一个arduinouno用于与visualstudio2010中的C++程序进行串行端口通信。我正在使用此处找到的代码:http://playground.arduino.cc/Interfacing/CPPWindows不幸的是,.cpp文件在第9行为变量“portName”提供了以下消息:错误:“char*”类型的参数与“LPCWSTR”类型的参数不兼容我不明白这个错误消息,并尝试了一些不同的方法来修复它。任何帮助将不胜感激! 最佳答案 鉴于您问题中的代码链接,问题似乎出在这里:Serial::Serial(cha

c++ - 为什么我不能像使用 std::string::size_type 那样使用 QList::size_type? (模板参数错误)

在我的for循环中声明迭代器时研究无符号整数与有符号整数比较警告时,Ireadthis:Wheneverpossible,usetheexacttypeyouwillbecomparingagainst(forexample,usestd::string::size_typewhencomparingwithastd::string'slength).我有一个QList我想迭代,使用上面的方法声明迭代器:for(QList::size_typei=0;i它给了我一个编译器错误:error:'templateclassQList'usedwithouttemplateparameters

c++ - vector 、Size_type 和封装

我有一个类,它有一个类型为vector的私有(private)数据成员.该类有两个实际使用vector::size_type的公共(public)方法:返回vector中元素个数的方法方法通过索引返回vector中的元素我可以将以下typedef添加到类的公共(public)部分:typedefvector::size_typeSIZE_t;但是恕我直言,它暴露了太多关于类实现的细节。另一种方法是使用size_t.你怎么看? 最佳答案 我会在类里面使用typedef。原因是对于std::vector,size类型是std::size

C++: 奇怪的 "Request for member X of Y which is of non-class type Z"

以下程序,用g++4.6编译,产生错误requestformember‘y’in‘a2’,whichisofnon-classtype‘A(B)’最后一行:#includetemplateclassA{public:Ty;A(Tx):y(x){}};classB{public:intu;B(intv):u(v){}};intmain(){intv=10;Bb1(v);//worksAa1(b1);//doesnotwork(theerroriswhena2isused)Aa2(B(v));//works//Aa2((B(v)));std::cout从代码中包含的工作变体可以看出,在A的

c++ - const_reference_type 不编译但 const value_type& 编译

#includetemplatestructref_exp{typedefTvalue_type;typedefvalue_type&reference_type;typedefconstreference_typeconst_reference_type;ref_exp(value_typedata):_data(data){}const_reference_typedata()const{return_data;}private:value_type_data;};intmain(){ref_expexp1(2);std::cout上面的代码无法编译ref.cpp:Inmember

c++ - "Expected constructor, destructor, or type conversion before ' < ' token"

我遇到语法/解析错误,但我似乎找不到它。DataReader.h:11:error:expectedconstructor,destructor,ortypeconversionbefore'这里是DataReader.h:#include#include#include#ifndefDATA_H#defineDATA_H#include"Data.h"#endifvectorDataReader();//Thisisline11,wheretheerroris..这是.cpp文件:#include"DataReader.h"usingnamespacestd;vectorDataRe