int main(){
printf("1:");
int i = CRO();
printf("2:");
float f = CRO();
printf("3:");
void p = CRO();
printf("4:");
CRO();
}
程序输出为:
1:int
2:float
3: void
4:void
请设计一个CRO()满足以上输出。
int main(){
printf("1:");
int i = CRO();
printf("2:");
float f = CRO();
printf("3:");
void p = CRO();
printf("4:");
CRO();
}
程序输出为:
1:int
2:float
3: void
4:void
请设计一个CRO()满足以上输出。
呵呵,这样行不行!
#include "stdafx.h"
#include <iostream>
using namespace std;
struct CRO
{
#define void void *
CRO() { type_ = "void"; }
~CRO() { cout << type_.c_str() << endl; }
operator int() { type_ = "int"; return 0; }
operator float() { type_ = "float"; return 0.0; }
operator void () { type_ = "void"; return 0; }
private:
string type_;
};
int main()
{
printf("1:");
int i = CRO();
printf("2:");
float f = CRO();
printf("3:");
void p = CRO();
printf("4:");
CRO();
system("PAUSE");
return 0;
}