0
我知道C++作爲一種編程語言的主要優點之一就是它可以支持OOP。C可以有物體嗎?
例子:
#include <iostream>
using namespace std;
class CRectangle {
int x, y;
public:
void set_values (int,int);
int area() {return (x*y);}
};
void CRectangle::set_values (int a, int b) {
x = a;
y = b;
}
int main() {
CRectangle rect;
rect.set_values (3,4);
cout << "area: " << rect.area();
return 0;
}
我在想,如果C還支持面向對象,如果是它是怎麼做。
你甚至可以在彙編中編寫OOP,但並不那麼容易。 – 2013-02-10 17:16:10