Linking problem

J

John J

I've written the following code to return the negative of a class object:

Length Length::eek:perator - ()

{

return Length (-nu, me);

}

The "nu" is an int and the "me" is a string. I use the following line of
code to test the function.

cout << "The negative of Length a is " << -a <<endl;

"a" is a Length object in the form of Length a (30, cm)

When I try to compile I get the following error.



Length.obj : error LNK2019: unresolved external symbol "class
std::basic_ostream<char,struct std::char_traits<char> > & __cdecl
operator<<(class std::basic_ostream<char,struct std::char_traits<char> >
&,class Length const &)"
(??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABVLength@@@Z)
referenced in function _main

Debug/Test.exe : fatal error LNK1120: 1 unresolved externals

I've tried everything I can to resolve this problem, but I can't seem to fix
it.



Tks for any help
 
M

Marty

John J said:
I've written the following code to return the negative of a class object:

Length Length::eek:perator - ()

{

return Length (-nu, me);

}

The "nu" is an int and the "me" is a string. I use the following line of
code to test the function.

cout << "The negative of Length a is " << -a <<endl;

"a" is a Length object in the form of Length a (30, cm)

When I try to compile I get the following error.



Length.obj : error LNK2019: unresolved external symbol "class
std::basic_ostream<char,struct std::char_traits<char> > & __cdecl
operator<<(class std::basic_ostream<char,struct std::char_traits<char> >
&,class Length const &)"
(??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABVLength@@@Z)
referenced in function _main

Debug/Test.exe : fatal error LNK1120: 1 unresolved externals

I've tried everything I can to resolve this problem, but I can't seem to fix
it.



Tks for any help

Perhaps overiding the << operator on your class and returning a stream from
it?
 
J

John J

I needed to create another object and assign the negative value to it.ie.

z = -a;
cout << z << endl;

It's now working fine.

Cheers
 
D

David Harmon

When I try to compile I get the following error.

Sez here it cannot find your operator <<. You have declared it,
but you have not connected up the definition.
Length.obj : error LNK2019: unresolved external symbol
....
operator<<( ostream &, class Length const &) [edited]
 
K

Kevin Goodsell

John said:
I needed to create another object and assign the negative value to it.ie.

z = -a;
cout << z << endl;

It's now working fine.

Then you've probably messed up your operator<<() parameters. Hard to say
for sure, though. Mostly because you failed to follow the guidelines in
section 5.8 of the FAQ. It always kind of surprises me that people want
help, but don't want to give us the relevant information.

"Please wash my car."
"OK. Uh... where's your car?"
"I don't think that's relevant."
"..."

-Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,825
Members
47,371
Latest member
Brkaa

Latest Threads

Top