Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Why does the compiler cannot pass?

Reply
Thread Tools

Why does the compiler cannot pass?

 
 
fl
Guest
Posts: n/a
 
      01-28-2013
Hi,
I am compiling the following program below the dot line, which is copied from a website. There are some link errors:

1> overload_Arrow0.cpp
1>overload_Arrow0.obj : error LNK2019: unresolved external symbol "public: struct A * __thiscall B:perator->(void)" (??CB@@QAEPAUA@@XZ) referenced in function _main
1>overload_Arrow0.obj : error LNK2019: unresolved external symbol "public: struct B __thiscall C:perator->(void)" (??CC@@QAE?AUB@@XZ) referenced in function _main
1>overload_Arrow0.obj : error LNK2019: unresolved external symbol "public: struct C __thiscall D:perator->(void)" (??CD@@QAE?AUC@@XZ) referenced in function _main

I do not solve this after several trials. What is wrong with the code?

Thanks a lot.

.......
#include <iostream>


struct A {
void foo();
};

void A::foo()
{
;
}


struct B { A* operator->(); };
struct C { B operator->(); };
struct D { C operator->(); };

int main()
{
D d;
d->foo();
}
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-28-2013
On 1/28/2013 11:07 AM, fl wrote:
> Hi,
> I am compiling the following program below the dot line, which is copied from a website. There are some link errors:
>
> 1> overload_Arrow0.cpp
> 1>overload_Arrow0.obj : error LNK2019: unresolved external symbol "public: struct A * __thiscall B:perator->(void)" (??CB@@QAEPAUA@@XZ) referenced in function _main
> 1>overload_Arrow0.obj : error LNK2019: unresolved external symbol "public: struct B __thiscall C:perator->(void)" (??CC@@QAE?AUB@@XZ) referenced in function _main
> 1>overload_Arrow0.obj : error LNK2019: unresolved external symbol "public: struct C __thiscall D:perator->(void)" (??CD@@QAE?AUC@@XZ) referenced in function _main
>
> I do not solve this after several trials. What is wrong with the code?


Just like your linker tells you, it cannot find those functions.

>
> Thanks a lot.
>
> ......
> #include <iostream>
>
>
> struct A {
> void foo();
> };
>
> void A::foo()
> {
> ;
> }
>
>
> struct B { A* operator->(); };
> struct C { B operator->(); };
> struct D { C operator->(); };


The three lines above define classes B, C, D, respectively, and each of
those classes *declares* operator->() function, but there is no
*definition* of those functions (B:perator->, etc.) in your code. You
should consider defining them since you actually call those in your
'main' program.

>
> int main()
> {
> D d;
> d->foo();
> }
>


V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 5.38 Why does Perl let me delete read-only files? Why does "-i" clobber protected files? Isn't this a bug in Perl? PerlFAQ Server Perl Misc 0 03-09-2011 11:00 PM
FAQ 5.38 Why does Perl let me delete read-only files? Why does "-i" clobber protected files? Isn't this a bug in Perl? PerlFAQ Server Perl Misc 0 02-11-2011 05:00 AM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Why is a JIT compiler faster than a byte-compiler RickMuller Python 4 03-26-2005 04:30 PM



Advertisments