Class method and variable with same name, compile error in C++ not in Java?

前端 未结 6 2105
执念已碎
执念已碎 2020-11-30 05:52
class Test {

      bool isVal() const {
          return isVal;
      }

  private:

      bool isVal;
};

On Compiling this file it says

6条回答
  •  遥遥无期
    2020-11-30 06:11

    Functions in c/c++ are just pointers to a location in memory where the code is located, isVal (as a boolean) and isVal (as a function) are therefore ambiguous.

提交回复
热议问题