# 新手为什么同一个程序中的虚函数，有一个不能运行

www.MyException.Cn  网友分享于：2013-02-16  浏览：7次

==========================================================================================================================

===========================================================================================================================
Shape.h
-------------------------------------------------
#ifndef SHAPE_H
#define SHAPE_H

#include <string>
using namespace std;

class Shape
{
public:
virtual double getArea() const;

virtual double getVolume() const;

virtual string getName() const = 0;
virtual void print() const = 0;
};

#endif

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Shape.cpp
----------------------------------------------------
#include <iostream>
using namespace std;

#include "shape.h"

double Shape::getArea() const
{
return 0.0;
}

double Shape::getVolume() const
{
return 0.0;
}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Point.h
--------------------------------------------------
#ifndef POINT_H
#define POINT_H

#include "shape.h"

class Point : public Shape
{
public:
Point( int = 0, int = 0 );

void setX( int );
int getX() const;

void setY( int );
int getY() const;

virtual string getName() const;

virtual void print() const;

private:
int x;
int y;
};

#endif

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Point.cpp
-----------------------------------------------------
#include <iostream>
using namespace std;

#include "point.h"

Point::Point( int xValue, int yValue ) : x( xValue ), y( yValue )
{

}

void Point::setX( int xValue )
{
x = xValue;
}

int Point::getX() const
{
return x;

void Point::setY( int yValue )
{
y = yValue;
}

int Point::getY() const
{
return y;
}

string Point::getName() const
{
return "Point";
}

void Point::print() const
{
cout << "[ " << getX() << ", " << getY() << " ]";
}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Circle.h
---------------------------------------------------
#ifndef CIRCLE_H
#define CIRCLE_H

#include "point.h"

class Circle : public Point
{
public:
Circle( int = 0, int = 0, double = 0.0 );

void setRadius( double );

double getDiameter() const;
double getCircumference() const;
virtual double getArea() const;

virtual string getName() const;

virtual void print() const;

private:
};

#endif

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Circle.cpp
-------------------------------------------------------
#include <iostream>
using namespace std;

#include "circle.h"

Circle::Circle( int xValue, int yValue, double radiusValue ) : Point( xValue, yValue )
{