草庐IT

class_list

全部标签

c++ - (SWIG C++ 到 Python)警告 301 : class keyword used, 但不是在 C++ 模式下

我正在尝试为python编译C++扩展。我创建了一个接口(interface)文件foo.i,如下所示:%modulefoo%include"typemaps.i"//Forpointerstoprimitivetypes%include"std_string.i"//std::stringmapping%applyconststd::string&{std::string*foo};//datatypescontainingstd::stringmembers%{#defineSWIG_FILE_WITH_INIT#include"../path/to/c++/header/file

c++ - initializer_list 和默认构造函数重载决议

#include#includeusingnamespacestd;structY{};structX{X(initializer_list){cout这会打印出“boo”。为什么它不打印出“yay”?无论如何要区分以下两种结构:X()X{}或returnX();返回{};或voidg(constX&)g(X())g({})谢谢。 最佳答案 Isthereanywaytodifferentiatethefollowingtwoconstructions:没有。它们不是不同的结构。{}构造函数语法的主要目的是引入统一初始化,让初始化工

c++ - 使用 std::list 提高简单性

有哪些更好(更清洁、更易读和/或更有效)的方法:std::listApples;std::listBasket;for(std::list::iteratorniApple(Apples.begin());niApple!=Apples.end();niApple++){for(std::list::iteratorniBasket(Basket.begin());niBasket!=Basket.end();niBasket++){if(&(*niBasket)==*niApple){Basket.erase(niBasket);break;}}//loop}//loop你会推荐什么

c++ - C++ 模板是否能够从父类获取 "forward any class function"?

classFoo{public:voidmethodA();};classManagedFoo{FoofooInst;public:voidmethodA(){doSomething();fooInst.methodA();}};现在我想把ManagedFoo做成一个模板,管理任何类而不仅仅是Foo,并且在调用Foo的任何函数之前,先调用doSomething。templateclassManager{_TyManaged_managedInst;voiddoSomething();public:/*Forwardeveryfunctioncalledby_managedInst*//

c++ - malloc 和堆 : extra memory for storing the size and linked list information?

我有一个关于heap和malloc的简单问题:当我们使用malloc分配一些内存空间时,如下所示:int*p;p=(int*)malloc(10*sizeof(int));它实际上在堆中分配了10个单词。但是,我的问题是:实际使用的内存空间真的是10个字?或者还有其他额外的空间需要存储内存大小的值?或者,甚至,因为堆的结构是链表,是否有其他内存空间用于存储指向堆中列表的下一个节点的地址? 最佳答案 它完全依赖于实现。a)它可以在每个分配的节点之前有几个字节,其中包含节点的大小、指向下一个节点的指针,可能还有前一个节点指针和节点类型。

c++ - 如何删除 STD::List 中最近的 "Point"对象到某个 x,y?

我有一个点类:classPoint{public:intx,y;Point(intx1,inty1){x=x1;y=y1;}};和点列表:std::listpointList;std::list::iteratoriter;我正在将点推送到我的pointList(尽管如果尚未推送任何点,该列表可能还不包含任何点)。我有两个问题:如何从列表中删除最接近任意点(x,y)的点?假设我有x,y(5,12),我想在列表中找到最接近该点的点并将其从STD::List中删除。我知道我必须使用距离公式并且我必须使用迭代器遍历列表但是我在概念化如何在我迭代时跟踪哪个点最近时遇到了一些问题通过列表。如何返

c++ - 关于 C++ 中 sizeof(class) 用法抛出的错误

当我用C++编译我的项目时,MSVC抛出以下错误:error#94:thesizeofanarraymustbegreaterthanzero执行sizeof时在以下行中抛出错误:if(sizeof(MyNamespace::MyClass)==60)MyClass是这样定义的:classMyClass:publicParentClass{public:MyClass(void*pCreate,inta,intb,boolc):ParentClass(pCreate,a,b,c){}virtualinlinevoidmyFunc(){//something}private:virtua

c++ - "Expected class-name"...析构函数实现中的问题

我正在尝试实现堆栈和队列。我还获得了用于测试堆栈和队列的代码(以查看它们各自的功能是否正常工作)。我已经实现了stack和quete的功能,但是在尝试编译它们时出现错误:在析构函数“Stack::~Stack()”中'('标记前的预期类名在他们两个。以下是通用的Stack类:templateclassStack{Listlist;public:Stack();Stack(constStack&otherStack);~Stack();}列表类:templateclassList{ListItem*head;public:List();List(constList&otherList);

c++ - 错误 : expected primary-expression before ‘>’ : templated function that try to uses a template method of the class for which is templated

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭8年前。在使用模板和仿函数(未出现在这个问题中)时,我最终遇到了以下简化的问题。以下代码(也可用here)classA{public:templateboolisGood(intin)const{constTf;returninbooltryEvaluator(T&evaluator,intvalue){returnevaluator.isGood(value);}intmain(intargc,constchar*argv[]

c++ - "class ClassName;"放在其他类定义的头文件中是什么意思?

我对这行代码classTreeItem;有点困惑。classTreeItem;在本文件中未包含的其他文件中定义。我必须在一本书中查找这个问题,但我确信这个问题的答案非常简单。#ifndefTREEMODEL_H#defineTREEMODEL_H#include#include#includeclassTreeItem;//here,whatdoesthisdo??//![0]classTreeModel:publicQAbstractItemModel{...public:...private:...};//![2]#endif//TREEMODEL_H