草庐IT

c++ - 错误 : invalid use of member in static member function

我有两个类,这是其中一个的标题:#ifndefWRAPPER_HPP#defineWRAPPER_HPP#includeusingnamespacestd;classWrapper{private://SDL_Surface*screen;public:staticSDL_Surface*screen;staticvoidset_screen(SDL_Surface*_screen);staticvoidset_pixel(intx,inty,Uint8color);staticvoidclear_screen(intr,intg,intb);staticSDL_Surface*loa

c++ - 现代 C 和 C++ : it is possible to use one defined structure for other declared structure?

假设我想制作某种支持加载图形Image的引擎,所以我有structImage;Image*load_image_from_file(...);我不想让外部世界知道Image到底是什么,他们只会处理指向它的指针。但是在engine内部我想使用特定的类型,例如SDL_Surface在SDL中完全定义。我能否以某种方式重新定义此文件的图像,以便编译器在每次看到Image*(宏除外)时都假定为SDL_Surface*?即我想要像typedefstructSDL_SurfaceImage;这样的东西所有的尝试都像usingImage=SDL_Surface;typedefSDL_SurfaceI

c++ - "potentially-evaluated"是否与 C++03 中的 "odr-used"相同?

举个例子:#includeclassA{public:staticconstintnumberOfWheels=4;};//constintA::numberOfWheels;intmain(){std::cout自A::numberOfWheels以来,它是否正式未定义的行为(UB)在没有定义的情况下被使用?(另请参见here)。正如C++03所述:Themembershallstillbedefinedinanamespacescopeifitisusedintheprogramandthenamespacescopedefinitionshallnotcontainaniniti

c++ - using 语句可以出现在构造函数初始化列表中吗?

如何将using语句合并到构造函数初始化列表中?例如,而不是foo::foo(inta,intb,intc):a(a),b(b),c(something_long::tada(c)){}我想拥有//Invokingsome'usingsomething_long::tada;'magicfoo::foo(inta,intb,intc):a(a),b(b),c(tada(c)){}大概这看起来有点像代码区域中所需的愚蠢的try/catch语法。在功能上,允许使用语句感觉很重要,因为something_long::tada(c)和usingsomething_long::tada;tada

c++ - 是否可以使用 'using' 来声明对 3 个整数类型别名的引用?

我得到了一个练习,我需要为“对3个整数的引用”使用类型别名。尽管我使用typedef获得了成功,但我无法通过c++11引入的复制它。代码:typedefint(&int_ref)[3];\\成功使用int_ref2=(int&)[3];\\错误我是否应该只使用类似...使用int_ref2=int[3];int_ref2&iruvar... 最佳答案 比较这两个声明typedefint(&int_ref)[3];\\successusingint_ref2=(int&)[3];\\error如您所见,存在差异:在第二个声明中,类型说

c++ - 不合格的名称查找 : Why local declaration hides declaration from using directive

考虑这段代码:namespaceA{inti=24;}namespaceB{usingnamespaceA;inti=11;intk=i;//findsB::i,noambiguity}和basic.lookup.unqual.2:§6.4.1Unqualifiednamelookup[basic.lookup.unqual]Thedeclarationsfromthenamespacenominatedbyausing-directivebecomevisibleinanamespaceenclosingtheusing-directive;see[namespace.udir].F

c++ - 在没有 USES_CONVERSTION 的情况下从 const char * 转换为 LPTSTR

我正在尝试将constchar*转换为LPTSTR。但我不想使用USES_CONVERSION来执行它。以下是我使用USES_CONVERSION进行转换的代码。有没有办法使用sprintf或tcscpy等进行转换?USES_CONVERSION;jstringJavaStringVal=(somevaluepassedfromotherfunction);constchar*constCharStr=env->GetStringUTFChars(JavaStringVal,0);LPTSTRlpwstrVal=CA2T(constCharStr);//Idonotwanttouset

c++ - 错误 C4703 : potentially uninitialized local pointer variable 'pNamesPtr' used

我正在做一个加密项目,在尝试编译程序时遇到了以下错误。main.cpp(520):errorC4703:potentiallyuninitializedlocalpointervariable'pNamesPtr'used==========Build:0succeeded,1failed,0up-to-date,0skipped==========DLLNAMES[i].UsedAlready=0;}*dwOutSize=(DWORD)pNamesPtr-(DWORD)pBuffer;//*有人可以帮我解决这个错误吗?您是否需要更多代码才能得到好的答案?

c++ - 如何在 C++ 函数之外限制 `using` 语句的范围?

我想定义一些模板特化的静态成员,像这样:namespaceA{templateintC::member1_=5;templateintC::member2_=5;templateintC::member3_=5;templateintC::member1_=6;templateintC::member2_=6;templateintC::member3_=6;...}但为了简化代码(并使其看起来更有条理),我想做这样的事情:namespaceA{{usingT=A1::A2::...::MyClass1;templateintC::member1_=5;templateintC::me

c++ - 为什么编译器说 : 'enable_if' cannot be used to disable this declaration

templateusingEnable_if=typenamestd::enable_if::type;classDegree;templateconstexprinlineboolIs_Degree(){returnstd::is_base_of::value;}classDegree{public:std::size_tinDeg=0;};templateclassVertex:publicSatellite{public:explicitVertex(intnum):n(num){}private:std::size_tn;};templateclassEdge{public:/