Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Why does the compiler cannot pass? (http://www.velocityreviews.com/forums/t957021-why-does-the-compiler-cannot-pass.html)

fl 01-28-2013 04:07 PM

Why does the compiler cannot pass?
 
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::operator->(void)" (??CB@@QAEPAUA@@XZ) referenced in function _main
1>overload_Arrow0.obj : error LNK2019: unresolved external symbol "public: struct B __thiscall C::operator->(void)" (??CC@@QAE?AUB@@XZ) referenced in function _main
1>overload_Arrow0.obj : error LNK2019: unresolved external symbol "public: struct C __thiscall D::operator->(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();
}

Victor Bazarov 01-28-2013 04:45 PM

Re: Why does the compiler cannot pass?
 
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::operator->(void)" (??CB@@QAEPAUA@@XZ) referenced in function _main
> 1>overload_Arrow0.obj : error LNK2019: unresolved external symbol "public: struct B __thiscall C::operator->(void)" (??CC@@QAE?AUB@@XZ) referenced in function _main
> 1>overload_Arrow0.obj : error LNK2019: unresolved external symbol "public: struct C __thiscall D::operator->(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::operator->, 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


All times are GMT. The time now is 12:46 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57