Tuesday, September 27, 2011

C++ in linux

did not try c++ in linux for a long time,

here is a example and how to compile it
code:
#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;
}


compile: g++ test1.cpp -o test1

run: /test1

No comments:

Post a Comment