GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-Jan-2005, 11:44
CaptnB CaptnB is offline
New Member
 
Join Date: Jan 2005
Posts: 16
CaptnB is on a distinguished road
Angry

friend functions error


Hi, I've just learned how to use the friend functions and I'm trying to overload operator<< for each of my classes so I can output data in a more efficient way.

For the moment, I've just added the declaration of the friend function into each of my classes and it seems to be OK for most of them except 2. Since I'm doing the same thing in each class, how is it possible to get errors in only 2 of them. Here's a sample:

CPP / C++ / C Code:
// Pt.h: interface for the CPt class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_PT_H__7A6EC590_A8CA_4458_A737_FF44E56ABDCA__INCLUDED_)
#define AFX_PT_H__7A6EC590_A8CA_4458_A737_FF44E56ABDCA__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CPt : public CObject  
{
private:
	// Member variables
	int m_ID;			// ID number
	double m_sta;		// Station (x coordinate)
	double m_bl;		// Butt line (y coordinate)
	double m_wl;		// Water line (z coordinate)
	CString m_type;		// Type of point (P = normal, A1 = begining of arc, A2 = end of arc, C = arc center, U = unknown, NULL = not defined

	// Friend functions
	friend ostream& operator<<(ostream &out, const CPt& Pt);

public:
	// Default constructor / destructor
	CPt();
	virtual ~CPt();

	// Copy constructor / operator overload
	CPt(const CPt& copy);
	CPt& operator=(const CPt& aff);

	// Get / Set functions
	int GetID();
	double GetSta();
	double GetBl();
	double GetWl();
	CString GetType();

	void SetID(int ID);
	void SetSta(double sta);
	void SetBl(double bl);
	void SetWl(double wl);
	void SetType(CString type);

	void Set(double sta, double bl, double wl);
	void Set(int ID, double sta, double bl, double wl, CString type);

	// Other functions
	void Translate(double delta_sta, double delta_bl, double delta_wl);
	void RotateAroundBl(double angle);
	void MirrorBl();
	CPt ProjectedOnLineAB(CPt PtA, CPt PtB);
};

#endif // !defined(AFX_PT_H__7A6EC590_A8CA_4458_A737_FF44E56ABDCA__INCLUDED_)

With the errors:
Code:
Pt.cpp d:\geardesign project\geardesign\pt.h(23) : error C2143: syntax error : missing ';' before '&' d:\geardesign project\geardesign\pt.h(23) : error C2433: 'ostream' : 'friend' not permitted on data declarations d:\geardesign project\geardesign\pt.h(23) : error C2501: 'ostream' : missing storage-class or type specifiers d:\geardesign project\geardesign\pt.h(23) : error C2244: 'ostream' : unable to resolve function overload d:\geardesign project\geardesign\pt.h(23) : error C2061: syntax error : identifier 'ostream' d:\geardesign project\geardesign\pt.h(23) : error C2501: '<<' : missing storage-class or type specifiers d:\geardesign project\geardesign\pt.h(23) : error C2805: binary 'operator <<' has too few parameters
  #2  
Old 21-Jan-2005, 12:41
CaptnB CaptnB is offline
New Member
 
Join Date: Jan 2005
Posts: 16
CaptnB is on a distinguished road
Forget it guys, I was just mixed up with header files, I cleaned up my mess and now it seems to work fine. Just a beginner mistake!
  #3  
Old 12-Jun-2006, 13:39
turtle21 turtle21 is offline
New Member
 
Join Date: Jun 2006
Posts: 1
turtle21 is on a distinguished road

Re: friend functions error


I know it has been awhile since this post was made...but, I am new to C++ development and am getting this exact error. Can you tell me how you resolved it?
 
 

Recent GIDBlogWriting a book by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] GUI programming with FLTK dsmith FLTK Forum 10 03-Oct-2005 15:41
What is "Ambigious symbol" ??*( a compilation error) small_ticket C++ Forum 2 07-Jan-2005 21:10
Error C2146: syntax error : missing ',' before identifier 'C4' mattchew008 C++ Forum 2 19-Dec-2004 06:06
Can enum have same name as class? crystalattice C++ Forum 3 08-Dec-2004 16:43

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:32.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.