Hi all and thanks in advance for your help !
I have a very simple class called circle and i wanna add the ostream << so i can have the ability in main to write cout<<a<<b<<c;
the theme is i'm getting many compile errors in the same row eg iso c++ forbids the declaration of ostream with no type
here's the code
circle.h
#ifndef CIRCLE_H
#define CIRCLE_H
class Circle
{
private : float radius;
public:
Circle();
Circle(float r);
float getarea();
float getperimeter();
friend ostream &operator(ostream &mystream,Circle &c);
};
#endif
circle.cpp
#define PI 3.14159
#include "circle.h"
using namespace std;
Circle::Circle()
{
radius=0;
}
Circle::Circle(float r)
{
radius=r;
}
float Circle::getarea()
{
return PI*radius*radius;
}
float Circle::getperimeter()
{
return Pi*2*radius;
}
ostream &Circle::operator(ostream &mystream,Circle &c)
{
mystream<<" radius "<<c.radius<<" area "<<c.getarea()<<" perimeter "<<c.getperimeter()<<endl;
return mystream;
}
main.cpp
#include <cstdlib>
#include <iostream>
#include "circle.h"
using namespace std;
int main(int argc, char *argv[])
{
Circle a(10);
Circle b(5);
Circle c(4);
cout<<a<<b<<c;
system("PAUSE");
return EXIT_SUCCESS;
}