寫出運行結(jié)果,在線等,挺急的?。?!
#include <iostream.h>class MyClass{char ch;public:MyClass();MyClass(char character);void Print();~MyClass();};MyClass::MyClass(){cout<<"This is a constructor!"<<endl;ch='a';}MyClass::MyClass(char character){cout<<"This is a constructor!"<<endl;ch=character;}void MyClass::Print(){cout<<"The value of ch is "<<ch<<endl;}MyClass::~MyClass(){cout<<"This is a destructor!"<<endl;}void main(){MyClass first,second('b');***.print();***.print();}
所給程序有錯,有許多全角字符,頭函數(shù)也寫錯了,等,,改正后的程序如下:
#include <iostream>using namespace std;class MyClass{char ch;public:MyClass();MyClass(char character);void Print();~MyClass();};MyClass::MyClass(){cout<<"This is a constructor!"<<endl;ch='a';}MyClass::MyClass(char character){cout<<"This is a constructor!"<<endl;ch=character;}void MyClass::Print(){cout<<"The value of ch is "<<ch<<endl;}MyClass::~MyClass(){cout<<"This is a destructor!"<<endl;}int main(){MyClass first,second('b');first.Print();second.Print();return 0;}
程序的運行結(jié)果:
Tags:在線