This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
operator<< overload question
- From: Allen Wayne Best <gcc at atoka-software dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 27 Dec 2003 09:31:11 -0800
- Subject: operator<< overload question
- Organization: Atoka Software
- Reply-to: gcc at atoka-software dot com
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