草庐IT

Non-declaration

全部标签

c# - "a field initializer cannot reference non static fields"在 C# 中是什么意思?

我不明白C#中的这个错误errorCS0236:Afieldinitializercannotreferencethenon-staticfield,method,orproperty'Prv.DB.getUserName(long)'对于下面的代码publicclassMyDictionary{publicdelegateVNonExistentKey(Kk);NonExistentKeynonExistentKey;publicMyDictionary(NonExistentKeynonExistentKey_){}}classDB{SQLiteConnectionconnecti

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++: 奇怪的 "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的

python - "Error: '::hypot ' has not been declared"在 cmath 中尝试嵌入 Python

在尝试使用#include将Python嵌入我的程序时遇到一些问题之后,我终于找到了所有正确的库,但我还有另一个错误。当我尝试使用#include进行编译时它会将我重定向到code::blocks目录中的cmath,并在显示using::hypot;的行放置一个错误标记并说:error:'::hypot'hasnotbeendeclared.我不知道为什么这是一个错误,特别是因为我的code::blocks安装时出现了这个错误,并且出现了,我想是因为Python试图包含它。我在Windows上,使用的是最新版本的Python(3.4.2) 最佳答案

c++ - 错误 : forward declaration of struct

我收到错误:proprietario.cpp:36:error:invaliduseofincompletetype‘structMotocicleta’proprietario.h:12:error:forwarddeclarationof‘structMotocicleta’摩托车.h:#ifndef__MOTOCICLETA__#define__MOTOCICLETA__#include#include"veiculo.h"#include"proprietario.h"usingnamespacestd;classProprietario;classMotocicleta:pu

c++ - 模板特化 : does not match any template declaration

我在学习模板特化的时候,用了一个很简单的例子,但是还是报错。#includetemplateclasschrrr{public:Tchgchr(Tc);};templateTchrrr::chgchr(Tc){returnc+1;}templateclasschrrr{public:charchgchr(charc);};templatecharchrrr::chgchr(charc){returnc+2;}usingnamespacestd;intmain(){chara='a';inti=1;chrrrit;chrrrch;cout错误说:line20:error:template

c++ - 何时以及为何会生成 std​​::__non_rtti_object 异常?

我正在使用VisualStudio并执行有效的动态转换。启用RTTI。编辑:更新代码使其更真实structbase{virtualbase*Clone(){base*ptr=newbase;CopyValuesTo(ptr);returnptr;}virtualvoidCopyValuesTo(base*ptr){...}virtual~base(){}}structderived:publicbase{virtualbase*Clone(){derived*ptr=newderived;CopyValuesTo(ptr);returnptr;}virtualvoidCopyValue

c++ - 哪个更好 : a lying copy constructor or a non-standard one?

我有一个包含不可复制句柄的C++类。但是,该类必须有一个复制构造函数。因此,我实现了一个将句柄的所有权转移到新对象的方法(如下所示),classFoo{public:Foo():h_(INVALID_HANDLE_VALUE){};//transferthehandletothenewinstanceFoo(constFoo&other):h_(other.Detach()){};~Foo(){if(INVALID_HANDLE_VALUE!=h_)CloseHandle(h_);};//otherinterestingfunctions...private:///disallowas

c++ - 为什么 VS 和 gcc 在这里调用不同的转换运算符(const vs non-const)?

这段代码当然很蠢,但我写它只是为了说明问题。在这里:#includeusingnamespacestd;structfoo{inta=42;templateoperatorT*(){cout(&a);}templateoperatorconstT*()const{cout(&a);}templateTget(){coutoperatorT();}};intmain(){foomyFoo;cout()使用VisualStudio2019(ISOC++17,/Ox)编译时的输出是:Tget()operatorconstT*()const42gcc8.3(-std=c++17,-O3)的输出

C++ 零规则 & 什么是 "user-declared"构造函数?

根据LightnessRacesinOrbit的说明,我缩小了我的帖子范围。看完这篇文章:TheRuleofZero,我明白了最多,但我还是想解决一些我遇到的不明白的问题:1.看这个短语:IfthedefinitionofaclassXdoesnotexplicitlydeclareamoveconstructor,onewillbeimplicitlydeclaredasdefaultedifandonlyif:Xdoesnothaveauser-declaredcopyconstructor,andXdoesnothaveauser-declaredcopyassignmentop