// test1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream.h"
//c++的基本类型你要记住 int bit long char strings float double
enum WeekDay {Sun,Mon,Th,We,Tus,Fri,Sat}; // 0...6
union Stuinfo { int Age;float Score; };
struct StuIn { char xm[20];
int age;
};
//自定义数据类型
typedef int INT;
typedef char Ch[80]; // char[80]
//内联函数
inline int rmax(int a,int b)
{
if (a>b)
return a;
else
return b;
}
//模板函数
template <typename T> //注意不要加分号
T rmin (T a,T b)
{
if (a<b)
return a;
else
return b;
}
//有了模板函数你就不用重载
// int rmin(int a,int b) {}
// float rmin(float a,float b) {}
//一个简单类的定义
class circle
{
private :
int x;
int y;
int r;
float getv();
protected:
float v;
public :
circle(int xx,int yy,int rr) //内部编写的函数
{
x=xx;
y=yy;
r=rr;
}
public :
float showV()
{
return getv();
}
};
//类的外部书写函数
float circle::getv()
{
v=(float)x*y*r;
return v;
}
int main(int argc, char* argv[])
{
INT c;
Ch s;
float f1,f2;
int a;
cout<<"请输入两个浮点数:";
cin>>f1>>f2;
cout<<rmin(f1,f2)<<endl;
cout<<"请输入两个浮点数:";
cin>>c>>a;
cout<<rmax(c,a)<<endl;
cout<<rmin(c,a)<<endl;
cout<<"请输入一个字符串:";
cin>>s;
cout<<sizeof(s)<<endl;
cout<<s<<endl;
circle p(1,2,3);
float vv;
// vv=p.showV; // 这个地方编译通不过
/*
E:\C\exam\test1\test1.cpp(95) : error C2440: '=' : cannot convert from 'float (__thiscall circle::*)(void)' to 'float'
There is no context in which this conversion is possible
执行 cl.exe 时出错.
*/
cout<<vv;
cin>>s; //让屏幕暂停
return 0;
}
下次解决.....