Well, I can't reproduce this error with any compiler. Try rebuilding. The only thing wrong is:
Code:
Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for ONLINE_EVALUATION_BETA2
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions
"ComeauTest.c", line 72: warning: expression has no effect
return a,b;
^
And this is what your code would look like with indentation:
Code:
#include <iostream>
using namespace std;
class Shape {
public:
Shape() {};
void print();
};
class TwoD:public Shape {
public:
TwoD( int a =0,int b = 0): length(a),width(b) {
setdata(a,b);
}
void setdata(int a,int b) {
length = a;
width = b;
}
void print() {
cout<<length<<','<<width<<endl;
}
protected:
int length,width;
};
class Threed:public TwoD {
friend ostream &operator<<(ostream &stream,Threed o);
friend Threed operator*(int Number,Threed o);
public:
Threed operator++();
Threed operator*(int Number);
Threed(int a =0,int b =0,int c =0):TwoD(a,b),height(c) {
setdata(a,b,c);
}
void print() {
cout<<length<<','<<width<<','<<height<<endl;
}
void setdata( int a, int b,int c) {
length = a;
width = b;
height = c;
}
protected:
int height;
};
Threed Threed::operator++() {
++length;
++width;
++height;
return *this;
}
Threed operator*(int number,Threed o) {
Threed a;
a.length= number*o.length;
a.width= number*o.width;
a.height= number*o.height;
return a;
}
Threed Threed::operator*(int number) {
Threed a,b;
a.length=b.length*number;
a.width=b.width*number;
a.height=b.height*number;
return a,b;
}
ostream &operator<<(ostream &stream, Threed o) {
stream << o.length <<endl;
stream << o.width << endl;
stream << o.height <<endl;
return stream; // must return stream
}
int main() {
Threed a(1,2,3),b(1,2),c(1);
++a;//prefix overloading
c = a*2;//use member function overloading
c= 2*a;//use global function overloading
return 0;
}