This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

operator<< overload question


hi:

i am attempting to overload the operator<< with the following function:

ostream& operator<<( ostream& o , const Sensor& s) 
{
	return o << "Name: " << endl
	<< "Port: " << s.get_port() << endl
	<< "Factor: " << s.get_conv() << endl
	<< "Raw Data: " << s.get_val() << endl
	<< "Value: " << s.get_val() * s.get_conv() << endl ;
}

in the header file, i declare this function as:

	class Sensor : public Probe
	{
	public:
		Sensor( long p = 0 , double c = 0.0 , int pd = 1 , char *nm = "") : 
			Probe( p , c , pd , nm ) { }

		...

		friend ostream& operator<<( ostream& o , const Sensor& s ) ;
	} ;

and it is used as:

		cout << "Air: " << airflow << endl ;

when i compile the code, i get the following (if i comment out the line above, 
all works well!)

g++  -g -O2   -o motor  motor.o sensor.o  
motor.o(.text+0x7cd): In function `main':
/home/best/engine-project/control-module/project/src/motor.cpp:67: undefined 
reference to `Measure::operator<<(std::basic_ostream<char, 
std::char_traits<char> >&, Measure::Sensor const&)'
collect2: ld returned 1 exit status

any suggestions are greatly appreciated! tia!

-- 
regards,
allen wayne best, esq
"your friendly neighborhood rambler owner"
"my rambler will go from 0 to 105"
Current date: 41:24:9::360:2003

Temporal anomaly


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]