草庐IT

external-sorting

全部标签

c++ - 类指针 vector 上的 std::sort()

我有一个类指针vectorstd::vectorlistSquares.我想用类的属性之一作为键对它进行排序。这就是我正在做的boolcompById(Square*a,Square*b){returna->getId()getId();}std::sort(listSquares.begin(),listSquares.end(),compById)但是编译器说:错误:没有匹配函数来调用'sort(std::vector::iterator,std::vector::iterator,)'我做错了什么? 最佳答案 为了使用comp

C++ 错误 LNK2001 : unresolved external symbol function _main

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Whatisanundefinedreference/unresolvedexternalsymbolerrorandhowdoIfixit?我正在学习C++,但在我的项目中遇到编译问题。我已经阅读了大量标题上有此错误的帖子,但我找不到问题出在哪里。我的Main函数中有一个方法调用是导致错误的原因。每当我评论该项目编译完美的行。代码如下:main.cpp#pragmaonce#include"stdafx.h"#include#include#include#include#include#include"N

c++ - extern 关键字真的有必要吗?

...#include"test1.h"intmain(..){countaaa定义在test1.h中,我没有使用extern关键字,但仍然可以引用aaa。所以我怀疑extern真的有必要吗? 最佳答案 extern有其用途。但它主要涉及不受欢迎的“全局变量”。extern背后的主要思想是用外部链接来声明事物。因此,它有点与static相反。但在许多情况下,外部链接是默认链接,因此在这些情况下您不需要extern。extern的另一个用途是:它可以将定义变成声明。示例:externinti;//Declarationofiwithe

c++ - extern "C"static void* 函数

在阅读了extern和static之后,我很困惑地遇到了具有以下行的代码:extern"C"staticvoid*foo(int*a){returnfoo1(a);}为什么这不会产生任何错误? 最佳答案 以下内容也编译并执行与您的行相同的操作:extern"C"{staticvoid*foo(int*a){returnfoo1(a);}}static意味着foo()将只在文件范围内可用,当它出现时它会覆盖extern"C"到联动。通常,extern"C"会影响链接器在导出时使用的函数的名称,以便在链接整个程序时可以从其他目标文件调用

c++ - 是否可以在 extern "C"函数中使用模板参数

我的要求是使用extern"c"函数从集合中获取一个项目。方法如下template>extern"C"__declspec(dllexport)_Ty*__cdeclGetItem(std::vector*itr,intindex){if(itr->size()at(index);}编译时出现如下错误errorC2988:unrecognizabletemplatedeclaration/definition这个extern方法的使用是使用c#中的pinvoke获取对象数据 最佳答案 不,那是不可能的。该标准禁止模板及其特化具有C链

c++ - 链接器错误 'unresolved external symbol' : working with templates

我有一个基于模板的类[Allotter.h&Allotter.cpp]:templateclassAllotter{public:Allotter();quint32getAllotment(allotType*);boolremoveAllotment(quint32,intauto_destruct=0);private:QVector>indexReg;intinit_topIndex;};它的用法如[ActiveListener.h&ActiveListener.cpp]所示:classActiveListener:publicQObject{Q_OBJECTpublic:Ac

c++ - 编译程序包含 extern "C"

我正在尝试使用makefile来编译其他人使用cygwin编写的程序。我收到很多错误消息,其中很多人提示error:templatewithClinkage.经过一番搜索后,问题似乎与extern"C"有关.此行包含在文件cygwin/usr/include/pthread.h中,该文件包含在#include中。在其中一个标题中。当我删除这一行时,大多数错误消息都消失了。但是还剩下一些,如下所示:/usr/include/pthread.h:67:5:error:previousdeclarationof‘intpthread_atfork(void(*)(),void(*)(),vo

c++ - std::sort 具有相等整数的行为

当std::sort与相等的整数一起使用时,它的行为是什么?它会让它们保持相同的顺序还是只是做一些不可预测的事情? 最佳答案 std::sort不保留等效元素的顺序,std::stable_sort做。但是,如果是int,您将不会注意到差异,除非您使用一些非平凡的顺序,如下例所示:structhalf_less{booloperator()(inta,intb)const{return(a/2)Hereisanotherexample当std::stable_sort比std::sort更合适时

解决python 3.11版本在linux ubuntu 23.04上使用pip命令报错:error: externally-managed-environment

报错error:externally-managed-environment×Thisenvironmentisexternallymanaged╰─>ToinstallPythonpackagessystem-wide,tryaptinstallpython3-xyz,wherexyzisthepackageyouaretryingtoinstall.Ifyouwishtoinstallanon-Debian-packagedPythonpackage,createavirtualenvironmentusingpython3-mvenvpath/to/venv.Thenusepath/to

c++ - 使用 extern const 将结构传递给模板。什么是外部?

我在问自己为什么下面的代码有效,以及说明符extern在实例化baz_instance时做了什么:structbaz{intvalue;};externconstbazbaz_instance={3};templateintfoo(){returnb.value;}intmain(){foo();return1;}为什么上面的代码首先编译,如果省略extern说明符,为什么它不再编译?extern说明符在此示例中的作用是什么? 最佳答案 这是从C++03到C++11的标准部分之一。在C++03中,[temp.arg.nontype]