请教c++高手一个关于继承中的重载有关问题用的是vc6.0
请问c++高手一个关于继承中的重载问题用的是vc6.0
#include <iostream>
#include <string>
using namespace std;
class Point
{public:
Point(float x = 0, float y = 0);
void setPoint(float, float);
float getX() const{return x;}
float gety() const{return y;}
friend ostream &operator < <(ostream &, const Point&);
protected:
float x, y;
};
Point::Point(float a, float b)
{
x = a;
y = b;
}
void Point::setPoint(float a, float b)
{
x = a;
y = b;
}
ostream &operator < <(ostream &output,const Point &p)
{
output < < "[ " < <p.x < < ", " < <p.y < < "] " < <endl;
return output;
}
int main()
{
Point p(3.5,6.4);
cout < < "x = " < <p.getX() < < ",y = " < <p.gety() < <endl;
p.setPoint(8.5,6.8);
cout < <p < <endl;
return 0;
}
--------------------Configuration: temp - Win32 Debug--------------------
Compiling...
temp.cpp
F:\编程\14\temp.cpp(30) : error C2248: 'x ' : cannot access protected member declared in class 'Point '
F:\编程\14\temp.cpp(12) : see declaration of 'x '
F:\编程\14\temp.cpp(30) : error C2248: 'y ' : cannot access protected member declared in class 'Point '
F:\编程\14\temp.cpp(12) : see declaration of 'y '
F:\编程\14\temp.cpp(36) : warning C4305: 'argument ' : truncation from 'const double ' to 'float '
F:\编程\14\temp.cpp(38) : warning C4305: 'argument ' : truncation from 'const double ' to 'float '
F:\编程\14\temp.cpp(39) : error C2593: 'operator < < ' is ambiguous
Error executing cl.exe.
temp.exe - 3 error(s), 2 warning(s)
是不是说的是《重载的参数不能调用基类的参数啊,可是我声明成了友元函数啊,找了好久就是没有找到问?
------解决方案--------------------
把VC6.0扔了,这玩意太老了。另外,程序无错。
------解决方案--------------------
#include <iostream>
#include <string>
using namespace std;
class Point
{public:
Point(float x = 0, float y = 0);
void setPoint(float, float);
float getX() const{return x;}
float gety() const{return y;}
friend ostream &operator < <(ostream &, const Point&);
protected:
double x, y;
};
Point::Point(float a, float b)
{
x = a;
y = b;
}
void Point::setPoint(float a, float b)
{
x = a;
y = b;
}
ostream &operator < <(ostream &output,const Point &p)
#include <iostream>
#include <string>
using namespace std;
class Point
{public:
Point(float x = 0, float y = 0);
void setPoint(float, float);
float getX() const{return x;}
float gety() const{return y;}
friend ostream &operator < <(ostream &, const Point&);
protected:
float x, y;
};
Point::Point(float a, float b)
{
x = a;
y = b;
}
void Point::setPoint(float a, float b)
{
x = a;
y = b;
}
ostream &operator < <(ostream &output,const Point &p)
{
output < < "[ " < <p.x < < ", " < <p.y < < "] " < <endl;
return output;
}
int main()
{
Point p(3.5,6.4);
cout < < "x = " < <p.getX() < < ",y = " < <p.gety() < <endl;
p.setPoint(8.5,6.8);
cout < <p < <endl;
return 0;
}
--------------------Configuration: temp - Win32 Debug--------------------
Compiling...
temp.cpp
F:\编程\14\temp.cpp(30) : error C2248: 'x ' : cannot access protected member declared in class 'Point '
F:\编程\14\temp.cpp(12) : see declaration of 'x '
F:\编程\14\temp.cpp(30) : error C2248: 'y ' : cannot access protected member declared in class 'Point '
F:\编程\14\temp.cpp(12) : see declaration of 'y '
F:\编程\14\temp.cpp(36) : warning C4305: 'argument ' : truncation from 'const double ' to 'float '
F:\编程\14\temp.cpp(38) : warning C4305: 'argument ' : truncation from 'const double ' to 'float '
F:\编程\14\temp.cpp(39) : error C2593: 'operator < < ' is ambiguous
Error executing cl.exe.
temp.exe - 3 error(s), 2 warning(s)
是不是说的是《重载的参数不能调用基类的参数啊,可是我声明成了友元函数啊,找了好久就是没有找到问?
------解决方案--------------------
把VC6.0扔了,这玩意太老了。另外,程序无错。
------解决方案--------------------
#include <iostream>
#include <string>
using namespace std;
class Point
{public:
Point(float x = 0, float y = 0);
void setPoint(float, float);
float getX() const{return x;}
float gety() const{return y;}
friend ostream &operator < <(ostream &, const Point&);
protected:
double x, y;
};
Point::Point(float a, float b)
{
x = a;
y = b;
}
void Point::setPoint(float a, float b)
{
x = a;
y = b;
}
ostream &operator < <(ostream &output,const Point &p)