TypeID

Hi there

I am running this example from book and there is something I don't understand
Output of this program should be


pointer to an object of: Derived1
pointer to an object of: Derived2


however I am getting:

pointer to an object of: 8Derived1
pointer to an object of: 8Derived2


I tried to debug and step it trough but it does comes in one step, why I am getting 8 next to Derived1 and Derived2 ??

thanks :)

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
#include <iostream>
#include <typeinfo>                                 // for typeid()
class Base
{
    virtual void virtFun()                              // required for typeid()
    {}
};
class Derived1 : public Base
{};

class Derived2 : public Base
{};

void displayName(Base* pBase)
{
    std::cout << "pointer to an object of: ";           // display name of the class
    std::cout << typeid(*pBase).name()  << std::endl;   // pointed to pBase
}

int main() {
    Base* ptrBase = new Derived1;
    displayName(ptrBase);                               // pointer to an object of class Derived1
    ptrBase = new Derived2;
    displayName(ptrBase);


    system("pause");
    return 0;
}
I do not get the 8 in front using Visual Studio.
1
2
3
pointer to an object of: class Derived1
pointer to an object of: class Derived2
Press any key to continue . . .


> why I am getting 8 next to Derived1 and Derived2 ??

See: http://www.cplusplus.com/forum/beginner/175177/
The 8 stems from a concept known as name mangling:

https://en.wikipedia.org/wiki/Name_mangling
Topic archived. No new replies allowed.