草庐IT

local-class

全部标签

c++ - 错误 : no type named ‘value_type’ in ‘class

我收到以下编译器错误:(graph_algorithms.h:59:111:error:notypenamed‘value_type’in‘classGraph::graph_algorithms::vertex_comparer’)这是什么意思?下一行给了我一大堆编译器错误std::priority_queue::vertex,typenameGraph::graph_algorithms::vertex_comparer>pri_que;#ifndefGRAPH_ALGORIUHMS_H_#defineGRAPH_ALGORIUHMS_H_#include#include"grap

c++ - 从 vector C++ 中的父类(super class)调用子类方法

我正在尝试将一些子类元素添加到一个vector中,遍历它们调用一个被覆盖的方法,并希望它在可能的情况下调用被覆盖的方法。但是我发现它似乎只调用父类(superclass)方法。我学过Java,但不确定为什么要在C++中这样做。我尝试使用父类(superclass)的指针vector重写代码并将子类的指针转换到父类(superclass)。然后通过指针访问它。理想情况下,我不想将指针列表放入vector中,因为我必须手动删除每个指针(我相信?)以阻止内存泄漏,因为我将使用new创建对象,以便它们持续到方法调用以将它们添加到vector中。有没有更好的方法来做到这一点,或者我是否坚持使用指

c++ - 构造函数执行顺序/顺序 : dependent initialization of static variable (class instance) in a function

对于以下代码段:classBar{public:intx;inty;Bar(int_x,int_y){/*somecodeshere*/...}};classFoo{public:intx;inty;intz;Foo(Barb):x(b.x),y(b.y){z=someFunction(x,y);}};voidf(intx,inty){Barb(x,y);staticFoox(b);}intmain(){f(2,3);}在我看来,函数内的静态变量甚至应该在main()之前初始化。但是,Foo类型的静态变量x依赖于Bar类型的局部变量b。问题是:1)x的构造函数什么时候执行?即x是在第一

c++ - 由于父类(super class)(按值传递)导致的重载构造函数调用不明确

我围绕GSL的某些部分编写了一些C++包装器并遇到了以下难题(对我来说)。代码(精简到最基本的部分)如下:#includestructgsl_vector_view{};classVector:protectedgsl_vector_view{public:Vector(constVector&original);Vector(constgsl_vector_viewview);};classAutoVector:publicVector{public:explicitAutoVector(constsize_tdims);};voiduseVector(constVectorb){}

c++ - 错误 : Invalid base class C++

谁能解释一下是什么导致了这个错误?Error:Invalidbaseclass我有两个类,其中一个派生自第二个:#if!defined(_CGROUND_H)#define_CGROUND_H#include"stdafx.h"#include"CGameObject.h"classCGround:publicCGameObject//CGameObjectissaidtobe"invalidbaseclass"{private:boolm_bBlocked;boolm_bFluid;boolm_bWalkable;public:booldraw();CGround();CGround

c++ - 将子类对象传递给采用父类(super class)对象的函数

假设以下代码:classEvent{public:virtualvoidexecute(){std::cout执行时,程序输出“Eventexecuted.”,但我想执行SubEvent。我该怎么做? 最佳答案 您正在按值传递Event。该函数获取自己的参数拷贝,这是一个Event对象,而不是SubEvent。您可以通过传递引用来解决此问题:voidexecuteEvent(Event&e){//^e.execute();}这叫做objectslicing.这相当于:SubEventse;Evente{se};e.execute()

c++ - `template <class> friend class Foo` 是什么意思?

我正在探索boost::iterator_facade并遇到了这段代码:friendclassboost::iterator_core_access;templatefriendclassIterator;第二行是什么意思?我熟悉friend类,但我想我没见过template在任何事情之前。这里是上下文:templateclassnode_iter:publicboost::iterator_facade,Value,boost::forward_traversal_tag>{public:node_iter():m_node(0){}explicitnode_iter(Value*p

c++ - 究竟什么时候初始化在全局范围内声明的 thread_local 变量?

例如:#includethread_localintn=1;voidf(){++n;//isninitializedhereforeachthreadorpriortoenteringf()?}intmain(){std::threadta(f);std::threadtb(f);ta.join();tb.join();}从here还不完全清楚n什么时候初始化。 最佳答案 足够简单,并且完全符合规范。n将在新线程运行时被初始化-在您输入任何线程特定的函数之前。准确的说是要初始化3次 关于

c++ - 通过 gcc-6 在 OSX Sierra 上安装时,保持 "FATAL:/opt/local/bin/../libexec/as/x86_64/as: I don' t 理解 'm' 标志!”错误

环境信息操作系统:macOS10.12.2(16C68)编译器:gcc-6重现步骤我已经安装了gcc-6并根据需要修改了config.mk到导出CC=gcc-6导出CXX=g++-6但是一直有这个错误:g++-6-c-std=c++0x-Wall-Wno-unknown-pragmas-Iinclude-Idmlc-core/include-Irabit/include-O3-funroll-loops-msse2-fPIC-fopenmpsrc/learner.cc-obuild/learner.oFATAL:/opt/local/bin/../libexec/as/x86_64/a

c++ - 错误 : class template partial specialization contains a template parameter that cannot be deduced

我很感激帮助弄清楚我的代码中出现的这个问题是怎么回事,我已将其简化为以下内容:typedefunsignedshortushort;templatestructFoo{};//Specialization--workswhennotaspecializationtemplateclassContainer,templateclass>classMetaFunction>structFoo::Type>>{//typedefContainer::Type>TestType;//OK};intmain(){}在编译(gcc5.4.0)时出现错误:Test.cpp:14:8:error:te