Is calling of overload operator-> resolved at compile time?
Posted
by Brent
on Stack Overflow
See other posts from Stack Overflow
or by Brent
Published on 2010-05-25T14:57:29Z
Indexed on
2010/05/26
1:31 UTC
Read the original article
Hit count: 225
c++
|operator-overloading
when I tried to compile the code: (note: func and func2 is not typo)
struct S
{
void func2() {}
};
class O
{
public:
inline S* operator->() const;
private:
S* ses;
};
inline S* O::operator->() const
{
return ses;
}
int main()
{
O object;
object->func();
return 0;
}
there is a compile error reported:
D:\code>g++ operatorp.cpp -S -o operatorp.exe
operatorp.cpp: In function `int main()':
operatorp.cpp:27: error: 'struct S' has no member named 'func'
it seems that invoke the overloaded function of "operator->" is done during compile time? I'd added "-S" option for compile only.
© Stack Overflow or respective owner