Why can't a class have same name for a function and a data member?

前端 未结 3 1821
眼角桃花
眼角桃花 2020-12-25 13:02

Why can\'t a c++ class have same name for a function and a data member?

class demo{
    public:
        int size();
    private:
        int size;   
};

in         


        
3条回答
  •  难免孤独
    2020-12-25 13:18

    because if you use size in your class somewhere then the compiler does not know what to do. It can be either the int-data-member or it can be the function-pointer. So the compiler is not able to seperate both kind

提交回复
热议问题