Skip to content

Instantly share code, notes, and snippets.

@popmentos
Created December 5, 2010 14:18
Show Gist options
  • Save popmentos/729116 to your computer and use it in GitHub Desktop.
Save popmentos/729116 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
class carcar{//使用純粹虛擬函數完成此類別
protected:
string name;
public:
virtual void move()=0;
};
class car :public carcar{ //使用虛擬函數完成此類別
public:
car(){this->name = "car";}
virtual void move(){cout << this->name << endl;}
} ;
class Benz: public car { //完成此類別
public:
Benz(){this->name = "Benz";}
void move(){cout << this->name << " in German" << endl;}
} ;
class Volvo: public car { //完成此類別
public:
Volvo(){this->name = "Volvo";}
void move(){cout << this->name << " in Sweden" << endl;}
} ;
void demo(car c){
c.move();
}
void demo(car *c){ //完成此函數
c->move();
}
//以下請勿更動
int main(){
car c;
Benz b ;
Volvo v;
cout << "傳入變數" << endl;
demo(c);
demo(b);
demo(v);
cout << "傳入指標" << endl;
demo(&c);
demo(&b);
demo(&v);
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment