草庐IT

using-declaration

全部标签

c++ - 警告 : function uses 'auto' type specifier without trailing return type

下面的代码给出了下面的警告。有人可以解释原因吗(请注意代码没有用,因为我用int替换了我的类型来制作一个完整的示例)。警告:“MaxEventSize()”函数使用“auto”类型说明符而没有尾随返回类型[默认启用]想法是获取特定结构的最大大小(类型位于int所在的位置)。templateconstexprTcexMax(Ta,Tb){return(a 最佳答案 auto返回类型“没有尾随返回类型”是C++14的一个特性,所以我想你正在编译C++11。您的代码适用于C++14,但对于C++11,如果您想使用auto作为返回类型,您需

C++ 错误 : definition of implicitly-declared

我正在用C++编写这个链表程序当我测试程序时,我得到了错误linkedlist.cpp:5:24:error:definitionofimplicitly-declared'constexprLinkedList::LinkedList()'LinkedList::LinkedList(){这是代码链表.h文件:#include"node.h"usingnamespacestd;classLinkedList{Node*head=nullptr;intlength=0;public:voidadd(int);boolremove(int);intfind(int);intcount(i

c++ - C++模板函数中,依赖函数调用为什么报 "not declared"错误?

在C++模板函数foo()中,调用::bar(TT*)在gcc4.4.3下会出现以下错误:g++-ohello.o-c-ghello.cpphello.cpp:Infunction'voidfoo(std::vector>&)':hello.cpp:8:error:'::bar'hasnotbeendeclared这是有问题的代码://hello.cpp#includetemplatevoidfoo(std::vector&vec){TT*tt;::bar(tt);vec.push_back(tt);}classBlah{};voidbar(Blah*&){}intmain(intar

【2024美赛】在COMAP比赛中使用大型语言模型和生成式AI工具的政策Use of Large Language ModelGenerative AI Tools in COMAP Contests

【2024美赛】在COMAP比赛中使用大型语言模型和生成式AI工具的政策UseofLargeLanguageModelGenerativeAIToolsinCOMAPContests写在最前面2024美赛翻译——跳转链接中文翻译在COMAP比赛中使用大型语言模型和生成式AI工具的政策团队指南当我们识别出可能是未声明使用此类工具准备的提交时,COMAP将采取适当行动。引用和参考文献指南AI使用报告英文原文UseofLargeLanguageModelsandGenerativeAIToolsinCOMAPContestsGuidanceforteamsCOMAPwilltakeappropria

c++ - 如何在 C++ 中使用 "using"关键字

对于命名空间使用usingC++关键字的更好方法,我有点困惑。假设下面的代码在头文件backtrace.h#includeusingmy_namespace1::component1;usingmy_namespace2::component2;namespacemy_application{namespaceplatform_logs{classbacktrace_log{//codethatcreatesinstancesofmy_namespace1::component1andmy_namespace2::component2};}}或#includenamespacemy_a

C++ 类型转换 : benefit of using explicit casts?

在C++中使用这些运算符而不是隐式转换有什么好处?dynamic_cast(expression)reinterpret_cast(expression)static_cast(expression)为什么、在哪里、在什么情况下我们应该使用它们?在OOP中很少使用它们是真的吗? 最佳答案 从您提供的转换列表中,唯一可以用来替代隐式转换的是static_cast。dynamic_cast用于将父类(superclass)向下转换为其子类。这不可能隐式发生,实际上在OOP中并不罕见。static_cast也可以用在这样的转换中,但是它更

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

我无法理解这个错误。这个错误不在我正在调试的类中。(是吗?)错误是:c:\programfiles\microsoftvisualstudio10.0\vc\include\fstream(890):errorC2248:'std::basic_ios::basic_ios':cannotaccessprivatememberdeclaredinclass'std::basic_ios'1>with1>[1>_Elem=char,1>_Traits=std::char_traits1>]1>c:\programfiles\microsoftvisualstudio10.0\vc\inc

c++ - 我可以在不更改 use_count 的情况下将 shared_ptr<T> & 转换为 shared_ptr<T const> & 吗?

我有一个使用boost::shared_ptr的程序s,特别是依赖于use_count的准确性执行优化。例如,假设一个加法运算有两个参数指针lhs和rhs。假设他们都有类型shared_ptr.当需要执行加法时,我会检查use_count,并且如果我发现其中一个参数的引用计数恰好为1,那么我将重新使用它来就地执行操作。如果两个参数都不能重用,我必须分配一个新的数据缓冲区并执行异地操作。我正在处理庞大的数据结构,因此就地优化非常有用。因此,我永远无法复制shared_ptr没有理由,即每个函数都采用shared_ptrs通过引用或const引用以避免扭曲use_count.我的问题是:我

C++11 decltype : How to declare the type that a pointer points to?

我有以下代码:#includeintmain(){int*a=newint(2);std::unique_ptrp(a);}导致这些错误信息:Infileincludedfroma.cpp:1:Infileincludedfrom/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/memory:81:/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/

c++ - GCC 编译错误 : declaration of ‘strlen’ must be available

我的问题是,当我想制作一个下载的库时,我从GCC得到了一些奇怪的编译错误。编译器要求更正的代码似乎是正确的。报错都是这样的:Catalogue.h:96:error:therearenoargumentsto‘strlen’thatdependonatemplateparameter,soadeclarationof‘strlen’mustbeavailable这是第96行附近的代码:GaCatalogueEntry(constchar*name,T*data){if(name){_nameLength=(int)strlen(name);//LINE96//copyname_name