Click to See Complete Forum and Search --> : Weird C++ Syntax


John
12-10-2001, 10:59 AM
Recently I came across a code having

--------------------
string FirstSymName = m_Operands[i]->GetSymbol()->GetDisplayName();
--------------------
m_Operands[i]->GetSymbol() is OK, but what is the meaninging of

GetSymbol()->GetDisplayName();


Thanks

mic
12-10-2001, 11:53 AM
most likely "m_Operands[i]->GetSymbol()" returns a pointer, which is then
used to call function GetDisplayName()...

<pointer>->GetDisplayName();

GetDisplayName() returns a string and assigns it to FirstSymName...

maybe this little bit of code can help you:

#include <string>
#include <iostream>

using namespace std;

class Test1
{
public:
Test1(string str){s=str;}
string ret_s(){return s;}

private:
string s;

};

class Test2
{
public:
Test2(Test1 *T){p=T;}
Test1 *ret_p(){return p;}

private:
Test1 *p;
};

void main()
{
Test1 *T1 = new Test1("Hello World");
Test2 *T2 = new Test2(T1);

string str2=T2->ret_p()->ret_s();

cout<<str2;
}

"John" <john_trivolta@planetaccess.com> wrote:
>
>Recently I came across a code having
>
>--------------------
>string FirstSymName = m_Operands[i]->GetSymbol()->GetDisplayName();
>--------------------
>m_Operands[i]->GetSymbol() is OK, but what is the meaninging of
>
>GetSymbol()->GetDisplayName();
>
>
>Thanks

john
12-10-2001, 01:04 PM
Thanks a lot mic...You are right !!!