草庐IT

Non-declaration

全部标签

c++ - 如何 'hide' 虚假 "declared but never used"警告?

我正在使用Borland(又名“Embarcodegearland”)C++Builder2007编译器,它有一个小错误,系统头文件中的某些staticconst项可能导致虚假的"xyzzy已声明但从未使用过”警告。我正试图让我的代码100%没有警告,所以想要一种屏蔽这些特定警告的方法(注意-但不是简单地关闭警告!)此外,我无法修改头文件。我需要一种“伪造”元素用途的方法,最好甚至不知道它们的类型。例如,将此函数添加到我的.cpp模块可修复这四个项目的警告,但它似乎有点“临时”。有没有更好的、最好是self记录的方式来做到这一点?staticintfakeUse(){returnOne

c++ - (Re)Using std::algorithms with non-standard containers

我有一个“列”容器类型:structMyColumnType{//Data:Eachrowrepresentsamemberofanobject.vectora;//Allvectorsareguaranteedtohavealwaysvectorb;//thesamelength.vectorc;voidcopy(intfrom_pos,intto_pos);//Thecolumntypeprovidesaninterfacevoidswap(intpos_a,intpos_b);//forcopying,swapping,...voidpush_back();//Andforres

c++ - MSVC : modifiers not allowed on non-memberfunction

我在linux下编写了一个信号/插槽库(Codeprojectarticlehere),同时使用Clang3.5和GCC4.9进行编译。它在两个编译器上编译时都没有警告(也在3.4版和4.8版上)。当我完成所有工作并将文章发布到网上时,没过多久我就收到投诉说它不能在MSVC上工作。(VisualStudioExpress2013?对不起,我对版本控制系统不熟悉。)我把它安装在虚拟机中自己看了一下,发现它不会编译以下内容:templatestructRemoveCV;templatestructRemoveCV{usingType=R(Args...);};templatestructR

C++ block scope extern declaration linkage,混淆C++标准解释

标准N3242(C++11草案)和N3797(C++14draft)两者有相同的段落。§3.5Programandlinkage[basic.link]¶6Thenameofafunctiondeclaredinblockscopeandthenameofavariabledeclaredbyablockscopeexterndeclarationhavelinkage.Ifthereisavisibledeclarationofanentitywithlinkagehavingthesamenameandtype,ignoringentitiesdeclaredoutsidethei

c++ - 使用 bind2nd() : "member function already defined or declared" instead of "reference to reference" 的奇怪编译器错误

我最近花了很多时间来理解在这段代码中调用func()时的错误消息:intmain(){vector>v;doublesum=0;for_each(v.begin(),v.end(),bind2nd(ptr_fun(func),&sum));return0;}当func()像这样声明时,代码编译正常:voidfunc(vectorv,double*sum){}当我使用这个声明(为了提高效率)时,我得到了一个编译器错误:voidfunc(constvector&v,double*sum){}我期望看到的错误类似于reference-to-reference错误,因为binder2nd的op

C++ 错误 : Member declaration not found

我是一个C++新手。今天遇到一个问题:在头文件中,我定义了一个类:templateclassPtr_to_const{private:Array_Data*ap;unsignedsub;public:...Ptr_to_const&operator=(constPtr_to_const&p);};在源文件中,我编程为:templatePtr_to_const&Ptr_to_const::operator=(constPtr_to_const&p){...return*this;}编译时,编译器总是说:'找不到成员声明'。为什么?我使用eclipseCDT+CygwinGCC非常感谢!

c++ - libc++ 与 VC++ : Can non-UTF conversions be done with wstring_convert?

C++11的std::wstring_convert效果很好*用于标准UTF-8UTF-16/UCS2/UCS4转换。但是,当我尝试使用不是来自的构面实例化wstring_convert或wbuffer_convert时,它没有按预期工作://worksasexpectedstd::wstring_convert>ucs4conv;//Now,byanalogy,Iwanttotrythis:std::wstring_convert>gbconv(newstd::codecvt_byname("zh_CN.gb18030"));Clang++错误提示“在~wstring_convert

c++ - 隐式转换 : const reference vs non-const reference vs non-reference

考虑这段代码,structA{};structB{B(constA&){}};voidf(B){cout这compilesfine,运行良好。但是,如果我将f(B)更改为f(B&),它doesn'tcompile.如果我写f(constB&),它又是compilesfine,运行良好。原因和道理是什么?总结:voidf(B);//okayvoidf(B&);//errorvoidf(constB&);//okay对于每种情况,我想听听语言规范中的原因、基本原理和引用资料。当然,函数签名本身并没有错。A隐式转换为B和constB&,但不会转换为B&,这会导致编译错误。

c++ - 错误 : uint64_t was not declared in this scope when compiling C++ program

我正在尝试一个简单的程序来打印steady_clock的时间戳值,如下所示:#include#includeusingnamespacestd;intmain(){cout(steady_clock::now().time_since_epoch()).count();cout但是每当我像这样编译时g++-oabcabc.cpp,我总是会遇到错误:Infileincludedfrom/usr/include/c++/4.6/chrono:35:0,fromabc.cpp:2:/usr/include/c++/4.6/bits/c++0x_warning.h:32:2:error:#er

c++ - 我可以用 C++ "forward declare"做什么?

我知道我能做到classFoo;可能structBar;和全局函数boolIsValid(intiVal);类型化的枚举呢?未声明类中的类型化枚举怎么样?带有未声明类的函数呢?未声明的类中的静态成员呢?未知命名空间中的这些怎么办?我是否遗漏了任何其他可以预先声明的内容? 最佳答案 可以转发声明模板,包括部分特化明确的特化嵌套类(这包括结构、“真实”类和union)非嵌套和本地类变量(“外部整数;”)职能如果“前向声明”是严格意义上的“声明但不定义”,您也可以前向声明成员函数。但是一旦它们被声明,你就不能在它们的类定义中重新声明它们。