草庐IT

C++ memory_order_consume, kill_dependency, dependency-ordered-before, 同步

我正在阅读C++ConcurrencyinAction安东尼·威廉姆斯。目前我在他描述memory_order_consume的地方。在那block之后有:NowthatI’vecoveredthebasicsofthememoryorderings,it’stimetolookatthemorecomplexparts这让我有点害怕,因为我不完全理解几件事:dependency-ordered-before与synchronizes-with有何不同?他们都创建了先发生后发生的关系。确切的区别是什么?我对以下示例感到困惑:intglobal_data[]={…};std::atomi

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++ - 这是正确的 : virtual method of Derived called before constructing Base object?

我知道在Base类的构造函数中-当调用虚拟方法时-调用Base方法,而不是派生-参见Callingvirtualfunctionsinsideconstructors.我的问题与这个主题有关。我只是想知道如果我在Derived类构造函数中调用虚拟方法会发生什么-但在构造Base部分之前。我的意思是调用虚方法来评估基类构造函数参数,请参见代码:classBase{public:Base(constchar*name):name(name){cout编译器g++(4.3.x-4.5x版本)输出为:Derived::getName()Base():DerivedDerived():Deriv

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++ - 错误 : expected primary-expression before X token

您能解释一下标题错误通常是什么意思吗?我有时会得到它,并且我总是最终会偶然修复它,但我仍然不知道它是什么意思。这是我当前错误的示例:Lcalca(graphList[0],dset,ss&);error:expectedprimary-expressionbefore')'token 最佳答案 如果没有任何示例很难判断,但IIRC发生这种情况是由于使用了undefinedsymbol(例如,没有声明的函数或类型——不确定到底是哪个)。因此,解析器会感到困惑,不知道代码中的进一步内容。-(我相信这个错误只会与其他错误一起出现?或者你能

我不明白的 C++ 错误 : syntax missing ';' before identifier

classDialogue{public:intid;inttrigger;Questiondescendants[5];//Maxquestionsperdialoguestringtext;};classQuestion{public:intid;intdescendant;intancestor;stringtext;};当我尝试构建它时,它说问题后代位出现以下错误?Error1errorC2146:syntaxerror:missing';'beforeidentifier'descendants'c:\users**\documents\visualstudio2012\pr

c++ - 最快的报价转义实现?

我正在编写一些规范化大量数据的代码。在处理结束时,许多key="value"对被写入文件。“值”部分可以是任何内容,因此在输出时,值必须将任何嵌入的引号转义为\"。现在,我正在使用以下内容:outstream但是,gprof显示我大部分执行时间都花在了这个方法上,因为我必须为每一行的每个值调用它。我很好奇是否有比这更快的方法。我不能使用std::replace,因为我要用两个字符替换一个字符。感谢您的任何建议。 最佳答案 如果速度是一个问题,您应该使用手写函数来执行此操作。请注意reserve()的使用,以尽量减少内存(重新)分配。

c++ - 继承 : expected class-name before ‘{’ token

我试图在C++中创建一个异常类,但它不起作用。我已将代码减少到最少,但仍然找不到错误。这是我的头文件:#ifndefLISTEXCEPTION_H#defineLISTEXCEPTION_H//C++standardlibraries#include/*CLASSDEFINITION*/classListException:publicexception{};#endif//LISTEXCEPTION_H这是我得到的错误:error:expectedclass-namebefore‘{’token这是出乎意料的。我该如何解决这个问题? 最佳答案