Overload dereference operator

前端 未结 3 477
没有蜡笔的小新
没有蜡笔的小新 2021-02-08 20:27

I\'m trying to overload the dereference operator, but compiling the following code results in the error \'initializing\' : cannot convert from \'X\' to \'int\':

3条回答
  •  既然无缘
    2021-02-08 21:15

    You should apply dereference operator to a class type. In your code x has a pointer type. Write the following:

    int t = **x;
    

    or

    int t = x->operator*();
    

提交回复
热议问题