【发布时间】:2015-02-21 20:11:00
【问题描述】:
我在 main.cpp 的单独文件中有一个类,它重载插入运算符。我的课是这样写的:
人.h
#ifndef PERSON_H_INCLUDED
#define PERSON_H_INCLUDED
#include <iostream>
class Person{
friend std::ostream& operator<<(std::ostream&, const Person&);
public:
Person(std::string);
protected:
std::string name;
};
#endif
Person.cpp
#include "Person.h"
using namespace std;
Person::Person(string name){
this->name = name;
}
ostream& operator<<(ostream& out, const Person& person){
out << "Name\t:" << person.name << "\n"; // Here's intellisense said error.
return out;
}
就在person.name Intellisense 说错误。我的观点是:
- 为什么它说错误,但我的代码仍然可以正常运行和构建?
- 是错误还是我做错了什么?
(我使用的是 Visual Studio 2010)
【问题讨论】:
-
智能感知错误不一定是编译器错误。 Intellisense 是一个单独的编译器,可以部分编译您的代码,以帮助在 Visual Studio IDE 中创建完成。
-
那么,可以忽略这种错误吗?
-
是的。可能它完全不知道
friend。 -
当我尝试使用 sn-ps 时,我确实看到某些东西以一种非常令人讨厌的方式爆炸。确保您的 .cpp 文件包含
#include <string>
标签: c++ visual-studio-2010 operator-overloading intellisense member