编译时出现C ++错误(C++ error when compile)
嗨,我正在做这个项目,当我编译它时,我收到一个错误。
ostream& operator<
os<
return os;
}
我得到的错误是:
error C2804: binary 'operator <
error C2333: '<
Hi I'm doing this project and when I compile it, I'm getting an error.
ostream& operator<
os<
return os;
}
and the error I get for this is :
error C2804: binary 'operator <
error C2333: '<
原文:https://stackoverflow.com/questions/15730062
更新时间:2020-01-31 22:01
最满意答案
您应该在类主体外部声明此函数,并在CService类内部将CService声明为朋友。 而且,不要忘记使类对象为const :
friend std::ostream& operator <
You should declare this function outside the class body and inside the CService class declare it as a friend. Moreover, don't forget to make the class object const:
friend std::ostream& operator <
2013-03-31
相关问答
它应该是 template
typename List::ListNode *List::find(int index) const
// ...
typename告诉编译器List::ListNode表示一个类型。 在模板内部时,遇到::时会出现解析歧义。 因此,当后面的任何内容::是一个类型时,你必须使用typename关键字。 It should be template
typename List::ListNod
...
摆脱#define末尾的分号(它是宏的一部分): #define LPAFDU LPBYTE
然而,更好的方法是使用typedef而不是#define : typedef LPBYTE LPAFDU;
typedef最重要的优点是它们遵守范围规则。 Get rid of the semicolon at the end of your #define (it's part of the macro): #define LPAFDU LPBYTE
A far better way to do
...
那是因为std::thread不能存储C ++引用,它类似于std::vector不能存在的方式。 因此,为了传递引用,标准库中有一个引用包装器 。 它基本上是引擎盖下的一个指针,它模仿了一些语言方面的引用行为。 std::ref和std::cref (用于const引用)函数用于创建std::reference_wrapper的对象(它们是方便的函数,因为它们具有模板类型推导和较短的名称)。 您在代码中添加的唯一内容是std::ref函数调用,如下所示: TestClass tc;
st
...
你需要包含字符串: #include
也就是说, 不要使用using namespace ! 特别是在文件范围内, 绝对不在头文件中。 现在任何包含此文件的单元都被迫屈服于std命名空间中的所有内容。 拿出来,并确定你的名字: bool filter(std::string word);
它的可读性也更具可读性。 另外,你应该将你的字符串作为const& : bool filter(const std::string& word);
避免不必要地复制字符串。 最后,你的头部
...
您缺少库引用。 检查您是否已导入代码所期望的.lib。 编辑:缺少的导入来自您正在谈论的库。 这可能表示您忘记导入该实际库的.lib,或者您需要将该项目中的.cpp文件附加到您自己的项目中。 换句话说,您需要的不仅仅是标题。 此外,如果您使用的是.NET,请考虑使用普通的Vista防火墙API,因为它已经作为COM coclass公开,.NET可以与本机进行通信。 You are missing a library reference. Check that you have imported t
...
您可以分配临时对象。 没有规则阻止这种情况。 如果您不希望在临时(在更常见的r值上)调用成员函数,则可以在函数声明中使用ref-qualifier 。 但是正如你在这里看到的那样, std::string::operator=没有ref-qualified版本。 我不认为标准委员会允许这种行为有一个明确的目标; 我想这个选择背后的基本原理是尽可能减少程序员的规则并让他找到一个有用的应用程序,如果有的话可以存在。 You can assign to temporary objects. There
...
似乎有些混乱。 你有#included fstream,那是C ++的一部分,而不是C. 由于某种原因,fstream似乎有自己的#include of cmath,而错误可能来自于C和C ++之间的不兼容性。 编辑: 是的,在#includes的几个级别之后,cmath是#included,而cmath不仅仅是math.h的副本,而且还包含特定于C ++的代码。 There seems to be some confusion. You have #included fstream, and t
...
您正在寻找的C ++功能是“静态类成员”。 这是语法: #include
#include
using namespace std;
class dayType
{
private:
string day;
static string week[];
public:
void Project113()
{
day = "Monday";
dayID = 0;
}
};
// No
...
该错误消息表明您正在使用MSVC。 它的库实现包含对谓词的调试检查。 特别是,对于偏序谓词(例如你的less ),我认为它测试Pred(a,b) && Pred(b,a) == false 。 显然这不会起作用。 (谓词的常见错误之一是人们习惯于定义一个命令,使得a分解,这就是为什么现在有一些调试检查为了防止这样的错误。如果你真的设法在运行时传递一对坏的a,b值,它们只能捕获错误;它们在编译时无法捕获理论错误) The error messa
...
您应该在类主体外部声明此函数,并在CService类内部将CService声明为朋友。 而且,不要忘记使类对象为const : friend std::ostream& operator <
You should declare this function outside the class body and inside the CService class declare it as a friend. Moreov
...