草庐IT

expectation-maximization

全部标签

c++ - 分配器 : how are the standard containers expected to work internally?

作为这个问题的示例,我将使用std::vector。它的定义来自documentation如下:template>class vector;正如预期的那样,如果T是它的类型,分配器应该偏向于T。总之,下面的代码编译没有错误(至少,使用GCC)并运行:#include#include#includestructS{inti;doubled;std::strings;};intmain(){std::allocatoralloc;std::vector>v{alloc};v.push_back(S{});}在这里,我通过使用专注于int的分配器创建vector的S。它是合法的代码吗?我应该

c++ - 为什么我得到 "error C2006: ' #include' : expected a filename, found 'identifier' "?

我在VisualC++Express2008中的源代码如下:#include“stdafx.h”#includeint_tmain(intargc,_TCHAR*argv[]){std::cout我正在使用IvorHorton的书VisualC++2008。这些是我遇到的错误。如何消除这些错误?1>e:\mydocuments\visualstudio2008\projects\hello\hello\hello.cpp(1):errorC2006:'#include':expectedafilename,found'identifier'1>e:\mydocuments\visual

c++ - 在 C 枚举错误中使用单词 "SING"到 "expected an identifier"

在头文件中我有以下枚举:namespaceOBJ_VERBS{enum{zero,CUDDLE,EMBRACE,FLIP,GROPE,HUG,KISS,LICK,NUDGE,PAT,PINCH,POKE,PULL,RUB,SHAKE,SQUEEZE,TAP,TUG,TURN,WAVE,PEER,PET,CLENCH,CURSE,NUZZLE,SNAP,STROKE,TWIRL,LEAN,GRIP,SMELL,GRUNT,SQUEAL,SCOLD,GAZE,WIND,SPIT,SPIN,DANCE,SING,zTOTAL};constint_MAX_=int(OBJ_VERBS::zTO

c++ - C++ : "expected primary-expression before ‘>’ token"中的两个模板

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭7年前。最小工作示例:#includestructPrinter{templatestaticvoidprint(Telem){std::coutstructMain{templatevoidprint(Telem){//Inthiscase,thecompilercouldguessTfromthecontext//Butinmycase,assumethatIneedtospecifyT.printer_t::print(e

c++ - C++ 代码错误 "expected constructor, destructor, or type conversion before ‘(’ token ”和 "no matching function for call to ..."

真正尝试解决错误,仔细检查所有内容。请帮忙。c++新手,请多关照。头文件(.h)#ifndefGUARD_Optimized_quick_sort_h#defineGUARD_Optimized_quick_sort_h#include#include#includeusingnamespacestd;templateclassoptimized_quick_sort{public:optimized_quick_sort(vectorarray){this->array=array;}optimized_quick_sort(listarray){vectortemp(array.b

C++套接字编程: maximize throughput/bandwidth on localhost (I only get 3 Gbit/s instead of 23GBit/s)

我想创建一个C++服务器/客户端,以最大化本地主机上TCP套接字通信的吞吐量。作为准备,我使用了iperf找出我的i7MacBookPro上的最大带宽是多少。------------------------------------------------------------ServerlisteningonTCPport5001TCPwindowsize:256KByte(default)------------------------------------------------------------[4]local127.0.0.1port5001connectedwith

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++ 模板 - 错误 : expected initializer before '<' token

我正在尝试学习模板,我希望我的类对能够容纳两个任何类型的对象。我现在只想为obj1提供一个访问器函数。但是当我尝试编译时出现以下错误:error:expectedinitializerbefore'::getObj1()我的代码是:#include#include#includeusingnamespacestd;templateclasspair{public:pair(constT1&t1,constT2&t2):obj1(t1),obj2(t2){};T1getObj1();private:T1obj1;T2obj2;};templateT1pair::getObj1(){ret

c++ - vector 声明 "expected parameter declarator"

这个问题在这里已经有了答案:Whycan'tmemberinitializersuseparentheses?(2个答案)关闭5个月前。我在类的私有(private)成员变量中有一行代码:vectordQdt(3)在xcode中编译时,会出现错误“expectedparameterdeclarator”。我想我提供了足够的信息。我认为此声明没有任何问题。