Shape.h
#ifndef SHAPE_H
#define SHAPE_H
#include <iostream>
using namespace std;
class Shape
{
public:
Shape();
~Shape();
double calcArea();
};
#endif
Shape.cpp
#include "Shape.h"
Shape::Shape()
{
}
Shape::~Shape()
{
}
double Shape::calcArea()
{
cout << "Shape->calcArea()" << endl;
return 0;
}
Circle.h
#ifndef CIRCLE_H
#define CIRCLE_H
#include "Shape.h"
class Circle :public Shape
{
public:
Circle(int r);
~Circle();
protected:
int m_iR;
};
#endif
Circle.cpp
#include "Circle.h"
Circle::Circle(int r) {
m_iR = r;
}
Circle::~Circle()
{
}
demo.cpp
#include "Circle.h"
int main(void)
{
Shape shape;
//cout << sizeof(shape) << endl; 1
int *p = (int *)&shape;
cout << p << endl;//00AFFEDB
cout << (unsigned int)(*p) << endl;//3435973836
Circle circle(100);
//cout << sizeof(circle) << endl; 4
int *q = (int *)&circle;
cout << q << endl;//00AFFCD8
cout << (unsigned int)(*q) << endl;//100
system("pause");
return 0;
}
Paste_Image.png