草庐IT

c++ - 专门化成员 S::display 需要 ‘template<>’ 语法

我正在创建一个特征类来帮助我的程序。我有一个名为operations的模板类包含方法display和area.当我定义这些函数时,我得到了错误。他们在这里:error:specializingmember‘traits::operations::display’requires‘template’syntaxerror:specializingmember‘traits::operations::area’requires‘template’syntax如您所见,编译器要我插入template就在这些定义之前。但是当我这样做时,我会收到一大页错误。出了什么问题,我该如何解决?这是我的程

c++ - 错误 : expected primary-expression before ‘int’

我正在使用:gcc--版本gcc(Ubuntu4.9.2-0ubuntu1~14.04)4.9.2我正在尝试编译以下程序:#include#includeusingnamespacestd;intmain(){cout但是得到如下错误:g++-fcilkplusCilk_1.cppCilk_1.cpp:Infunction‘intmain()’:Cilk_1.cpp:9:12:error:expectedprimary-expressionbefore‘int’cilk_for(inti=0;i怎么了?谢谢 最佳答案 来自linkC

C++ 在 ‘value_type’ 中没有名为 ‘struct std::iterator_traits<int>' 的类型

你好。我正在尝试运行以下代码(仅用于培训目的):#include#includetemplate>classkont>typenamestd::iterator_traits::value_typefoo_test(typenamekont::iteratorb){return*b;}templatetypenamestd::iterator_traits::value_typeminimum(Iterb,Itere){Iterm=b;/*CODE*/return*m;}intmain(void){std::listx;x.push_back(10);x.push_back(100);

c++ - 编译器错误 : ‘std::array<...>::~array()’ is implicitly deleted

我有以下.hpp文件:#ifndefCODE_HPP#defineCODE_HPP#include#includeusingstd::vector;usingstd::array;template>classstack;template,typenameK=stack>classstack_array;templateclassstack{Cpile;stack();~stack();voidpush(T&);friendclassstack_array>;};templateclassstack_array{private:staticconstsize_tmax_elem=10;a

c++ - 重载 ‘QString(int)’ 不明确

下面的代码片段给出了编译错误重载“QString(int)”的调用不明确与qt4.7.3(系统是linux64bit,debian不稳定)structQSAConnection{QSAConnection():sender(0),signal(0),function_ref(){}QSAConnection(QObject*send,constchar*sig,QSObjectref):sender(send),signal(QLatin1String(sig)),function_ref(ref){}QObject*sender;QStringsignal;QSObjectfunct

C++ 编译错误 - ‘operator=’ 不匹配

下面的代码编译没有问题classMyClass{public:MyClass(){std::cout但是当我将赋值运算符参数更改为非常量时编译器打印错误:MyClass&operator=(MyClass&m){std::cout我想知道原因。提前致谢。 最佳答案 因为MyClass&使没有const的operator=不是正确的赋值运算符。它必须是operator=(constMyClass&)(或operator=(MyClass)但不要那样做,除非你知道自己在做什么,copy-&-swap。..).否则,您的代码d=MyCla

c++ - 错误 : cannot declare variable ‘bg’ to be of abstract type ‘cv::BackgroundSubtractorMOG2’ in OpenCV 3

我最近在我的ubuntu14.10系统中安装了OpenCv并且我正在运行一个程序并且正在运行cv::BackgroundSubtractorMOG2我遇到了一个错误。错误是cannotdeclarevariable‘bg’tobeofabstracttype‘cv::BackgroundSubtractorMOG2’为什么我会遇到这个错误我的代码示例intmain(intargc,char*argv[]){Matframe;Matback;Matfront;vector>hand_middle;VideoCapturecap(0);BackgroundSubtractorMOG2bg;

c++ - "integer constant is too large for ‘long’ 求最大质因数时键入"

我正在解决Euler项目3:Description:Theprimefactorsof13195are5,7,13and29.Whatisthelargestprimefactorofthenumber600851475143?这是我生成答案的代码。但是我需要一个整数类型来保存600851475143。当我在Mac上的GCC上编译它时,我得到:integerconstantistoolargefor‘long’type".我预计longlong可以轻松持有这个数字。我也试过让它未签名。为什么我的代码不能保存这么小的数字?我该怎么做才能让它发挥作用?#include#includeusi

c++ - 访问声明已弃用,取而代之的是使用声明;建议 : add the ‘using’ keyword

我回到了我以前的C++学校作业中,它实现了一个二叉树。我有一个文件(Tree.cpp),其中包含用于插入、查找、删除等节点的函数。在顶部,我有“usingnamespacestd;”。我收到的警告是由另一个文件SymTab.hpp引起的,它看起来像这样:#ifndefSYMTAB_H#defineSYMTAB_H#include#include"Tree.hpp"usingnamespacestd;templateclassSymTab:privateTree{public:Tree::Insert;Tree::Lookup;Tree::Remove;Tree::Write;Tree:

c++ - ‘operator ==’ 中的 ‘a == b’ 不匹配

#includeusingnamespacestd;classfamily{private:doubleweight;doubleheight;public:family(doublex,doubley);~family();doublegetWeight();doublegetHeight();doublesetWeight();doublesetHeight();booloperator==(constfamily&,constfamily&);};boolfamily::operator==(constfamily&a,constfamily&b){return(a.getWei