草庐IT

implicitly-declared

全部标签

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

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

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++ - 错误 : 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)非嵌套和本地类变量(“外部整数;”)职能如果“前向声明”是严格意义上的“声明但不定义”,您也可以前向声明成员函数。但是一旦它们被声明,你就不能在它们的类定义中重新声明它们。

c++ - 为什么 gcc 提示 "declaration of ' foo' 隐藏了之前的调用 [-Werror=shadow]”

我有这个MCVE:autobar()->double{return8.0;}intmain(){if(autofoo=bar()){returnfoo;}elseif(autofoo=bar()){returnfoo;}}使用gcc7.3和这些选项-c-Werror-Wextra-Wall-Wshadow编译它会生成以下错误消息:test-shadow.cpp:Infunction‘intmain()’:test-shadow.cpp:9:17:error:declarationof‘foo’shadowsapreviouslocal[-Werror=shadow]elseif(aut

c++ - 错误 : out-of-line definition of 'test' does not match any declaration in 'B<dim>'

我有一个小问题让我很烦!!我不知道下面的代码似乎有什么问题。我应该能够实现从父类(superclass)继承的功能,不是吗?但我得到error:out-of-linedefinitionof'test'doesnotmatchanydeclarationin'B'templateclassA{public:virtualdoubletest()const;};templateclassB:publicA{};templatedoubleB::test()const{return0;}我在Mac上使用clang(AppleLLVM5.1版)。 最佳答案

c++ - 错误 C2248 : 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'

收到此错误,我很确定它在operatorvoidCRational::print()const{print(cout);}voidCRational::print(ostream&sout)const{if(m_denominator==1)cout 最佳答案 您需要通过引用而不是值返回ostream。它试图调用构造函数。也可以传递'a'作为引用:ostream&operator我还注意到打印方法可能是错误的。它有sout作为流的名称传递,但随后直接使用cout实现。应该是voidCRational::print(ostream&s

c++ - "a declaration shadows a parameter"是什么意思?

我正在尝试创建一个函数,该函数返回我将传递给它的整数的两倍。我的代码收到以下错误消息:declarationof'intx'shadowsaparameterintx;"这是我的代码:#includeintdoublenumber();usingnamespacestd;intdoublenumber(intx)//>a;doublenumber(a);return0;} 最佳答案 您将x作为参数,然后尝试将其也声明为局部变量,这就是对“阴影”的提示。 关于c++-"adeclarati