Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 26th, 2006, 12:00 AM   #1
sobank
Newbie
 
Join Date: Mar 2005
Posts: 4
Rep Power: 0 sobank is on a distinguished road
Problem with << overlaoding

well i am trying to overload <<. And i am getting the errors that i have no idea how to fix.

here is the header file.

#define MAX_FILENAME 21

class DataPoint {
double x;
double y;
public:
DataPoint();
~DataPoint();
double getx() const;
double gety() const;
friend bool operator==(const DataPoint&, const DataPoint&);
int loadFromFile(FILE*);
bool saveToFile(FILE*);
void xStore(double);
void yStore(double);
};

class DataSet {
DataPoint* points;
int n; //number of records
char dataLabel[MAX_FILENAME];//label
double t; //slope
double r; //correlation
double b; //intercepts
double m; // mean
double d; // standard deviation
double tol; //tolorence

public:
DataSet();
~DataSet();
DataSet(const DataSet&);
void include();
void include(const double);
bool outlier(int) const;
bool saveToFile(const char* filename);
int outlier()const;
void display() const;
DataSet& operator=(const DataSet&);
bool loadFromFile(const char*);
const char* label() const;
double slope() const;
double intercept() const;
double correlation() const;
int nPoints() const;
DataPoint point(int) const;
void setlabel(const char*);
void sum(int,const double*, const double*);
double mean() const;
double stdDev() const;
double tolorence() const;
void memCreate(int);
friend bool operator==(const DataSet&, const DataSet&);
friend DataSet operator+(const DataSet&, const DataSet&);
friend ostream& operator<<(ostream&, const DataSet&);
};


now in .cpp file I try to overload the << operator

ostream& operator<<(ostream& os, const DataSet& ds){
os<<left<<setw(10)<<ds.slope()<<setw(15)<<ds.intercept()<<setw(15)<<ds.correlation()<<setw(30)<<ds.label()<<endl;
return os;
}

and these are the list of errors that i am getting on visual studio

------ Build started: Project: assignment 333, Configuration: Debug Win32 ------
Compiling...
DataSet.cpp
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.h(55) : error C2143: syntax error : missing ';' before '&'
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.h(55) : error C2433: 'ostream' : 'friend' not permitted on data declarations
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.h(55) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.h(55) : error C2061: syntax error : identifier 'ostream'
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.h(55) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.h(55) : error C2805: binary 'operator <<' has too few parameters
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.cpp(408) : error C2872: 'ostream' : ambiguous symbol
could be 'd:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.h(55) : int ostream'
or 'c:\program files\microsoft visual studio 8\vc\include\iosfwd(701) : std::ostream'
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.cpp(408) : error C2143: syntax error : missing ';' before '&'
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.cpp(408) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.cpp(408) : error C2086: 'int ostream' : redefinition
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.h(55) : see declaration of 'ostream'
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.cpp(408) : error C2872: 'ostream' : ambiguous symbol
could be 'd:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.h(55) : int ostream'
or 'c:\program files\microsoft visual studio 8\vc\include\iosfwd(701) : std::ostream'
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.cpp(408) : error C2872: 'ostream' : ambiguous symbol
could be 'd:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.h(55) : int ostream'
or 'c:\program files\microsoft visual studio 8\vc\include\iosfwd(701) : std::ostream'
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.cpp(408) : error C2065: 'os' : undeclared identifier
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.cpp(408) : error C2059: syntax error : 'const'
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.cpp(408) : error C2143: syntax error : missing ';' before '{'
d:\my documents\visual studio 2005\projects\assignment 333\assignment 333\dataset.cpp(408) : error C2447: '{' : missing function header (old-style formal list?)
Generating Code...
Compiling...
regressionF.cpp
Generating Code...
Build log was saved at "file://d:\My Documents\Visual Studio 2005\Projects\assignment 333\assignment 333\Debug\BuildLog.htm"
assignment 333 - 16 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



I have tried to match them with prof. lectures but it looks like every thing is right.

Any idea????????????????????????
sobank is offline   Reply With Quote
Old Jun 26th, 2006, 12:22 AM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 914
Rep Power: 4 The Dark is on a distinguished road
1. You need to post code inside [ code ] tags (no spaces) - this preserves indentation and makes it easier for people to answer you.
2. You need to include <ostream> before you include your .h file (or include <ostream> inside your include file)
3. You either need to use std:: in front of your use of ostream in your .h file (recommended), or put "using namespace std;" at the top of your include file (not recommended).

The errors are because the C compiler does not know, at line 55 in your include file, what "ostream" is. This is either because of 2 or 3 above.
The Dark is offline   Reply With Quote
Old Jun 26th, 2006, 1:05 AM   #3
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 773
Rep Power: 3 Jimbo is on a distinguished road
you can also put
using std::ostream;
if you don't want to put the std:: prefix everywhere and not use the whole std namespace.
Jimbo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:03 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC