'class' keyword in variable definition in C++

前端 未结 3 1345
天命终不由人
天命终不由人 2020-12-17 10:59

Before anyone asks, yes, this is part of a homework, and yes, I did a lot of Googling before asking. I spent the last hour searching intensively on Google with many, many di

3条回答
  •  温柔的废话
    2020-12-17 11:19

    Actually it is optional to use class while creating object of class. In C language it is compulsory to use struct in front of struct name to create its variable. As C++ is superset of C. There is only one difference between struct and class in C++, and that is of access modifier.

    To keep backward compatible it is permissible.

    So,

    class MyClass* myClass = new MyClass();
    

    And,

    MyClass* myClass = new MyClass();
    

    Both are same.

提交回复
热议问题