Why can't I inherit from int in C++?

前端 未结 19 2290
不知归路
不知归路 2020-12-02 18:24

I\'d love to be able to do this:

class myInt : public int
{

};

Why can\'t I?

Why would I want to? Stronger typing. For example, I

19条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 18:29

    If I remember, this was the main - or one of - the main reasons C++ was not considered a true object oriented language. Java people would say: "In Java, EVERYTHING is an object" ;)

提交回复
热议问题