错误代码如下:
#ifndef _Point_h_
#define _Point_h_
#include "stdafx.h"
#include<iostream>
using namespace std;
class point
{
public:
point(double m,double n);
~point(){};
point& operator ++();
point operator ++(int);
point& operator --();
point operator --(int);
friend ostream& operator << (ostream& o,point& p);
private:
double x;
double y;
};
#endif
类的实现:
#include "stdafx.h"
#include"Point.h"
#include<iostream>
#include<ostream>
using namespace std;
//函数的实现
point::point(double m,double n)
{ x=m;
y=n;
}
point& point:: operator ++() //如果返回值不是应用,就不能进行取址运算,只是一个临时变量。++a=5
{
++x;
++y;
return *this;
}
point point:: operator ++(int)
{
point old=(*this);
++(*this);
return old;
}
point& point:: operator --()
{
--x;
--y;
return *this;
}
point point:: operator --(int)
{
point old=(*this);
--(*this);
return old;
}
ostream& point:: operator <<(ostream& o,point& p)
{
.....................
}
注意:frinend 关键字函数 并不是类的成员函数 ,所以在友元函数时不能像成员函数一样用类的::来限定;
所以 要把友元函数的实现改为:
ostream& operator <<(ostream& o,point& p)
{
.....................
}
博客内容讲述了在C++编程中遇到的一个错误:IntelliSense提示point类没有成员'operator<<'。作者分析了错误原因,并提供了修复方案。错误源于在实现友元函数`ostream& operator<<(ostream& o, point& p)`时,不应该使用类的成员访问操作符`::`。正确的实现方式是将友元函数作为独立函数定义,不与任何类绑定。"
6786145,1167829,Hibernate连接配置与数据库连接池,"['数据库连接池', 'Hibernate', 'schema', 'c3p0', 'session']
4009

被折叠的 条评论
为什么被折叠?



