c++项⽬导⼊头⽂件声明及定义代码如下:
Shape.h
#ifndef SHAPE_H_INCLUDED
#define SHAPE_H_INCLUDED
class Shape{
public:
virtual float GetPircumference()=0;
双飞人药水
};
class Rectangle:public Shape
{
private:
float R_a;
float R_b;
public:
Rectangle(float a,float b);
float GetPircumference();
};
class Circle:public Shape
{
private:
float C_a;
public:
Circle(float a);
float GetPircumference();
};
#endif// SHAPE_H_INCLUDED
画动画人物Shape.cpp
#include<iostream>
#include"Shape.h"如何杀蟑螂
//Rectangle::Rectangle(int a,int b):Rectangle::R_a(a),R_b(b){}//这种初始化⼀般⽤在没有分头⽂件声明和具体实现,this⽤的多Rectangle::Rectangle(float a,float b)
{
this->R_a =a;
this->R_b =b;
}
float Rectangle::GetPircumference()
{
float R_c =0;
R_c =2*(this->R_a + this->R_b;
return R_c;
古开头的四字成语}
宁波怎么样
//Circle::Circle(int a):Circle::C_a(a){}
Circle::Circle(float a)
{
this->C_a =a;
}
float Circle::GetPircumference()
{
float R_c =0;
R_c =2*this->C_a*3.14;
return R_c;
}
main.cpp
#include<iostream>
#include"Shape.h"
using namespace std;
int main()
{
Shape *rect =new Rectangle(3,4);
cout <<rect->GetPircumference()<<endl;
横折钩的拼音Shape *cirle =new Circle(5);
cout <<cirle->GetPircumference()<<endl;
return0;
秋天的四字词语有哪些}
编译出错:
解决办法:
右键点击项⽬
然后把未勾选的都选上并点击OK
古诗鹅鹅鹅
最后重新编译运⾏问题原因:
新建file时候(.h或者.cpp)未勾选编译类型
参考:blog.csdn/lonely_gfwolf/article/details/77837650