Error:cannot call member function without object
程序员文章站
2022-05-30 21:34:59
...
class Base {
public:
void virtual f() = 0;//纯虚函数
void virtuL g() { cout << "Base::g()" << endl;
};
int main() {
Base::g();
}
运行以上函数时(只是想测试一下抽象类的函数能否被调用),出现了题目所示的错误,查阅相关资料,发现是因为
没有把成员函数声明为static函数,否则需要通过对象来调用函数,通常成员函数在调用时* this指针*时被当作参数传进。,因此一个const对象不能调用非const函数(此时传入的是const this指针),但是非const对象可以调用const对象,因为会发生隐式转换。
上一篇: recoil error Cannot assign to read only property of object ‘#‘
下一篇: configure: error: cannot compute suffix of object files: cannot compile
推荐阅读
-
jQuery的$.get()函数不执行以及php端报错Uncaught Error: Call to a member function bind_param() on boolean in...
-
php用mysqli模块连数据库Fatal error: Call to a member function query() 。解决思路
-
求大神纠错,多谢!Fatal error: Call to a member function query() on a non-object
-
Call to a member function fetch() on a non-object异常
-
Fatal error: Call to a member function fetch_array() on a non-object in 62 line
-
Wordpress PHP Fatal error: Call to a member function get()
-
php中出现“Call to a member function Execute() on a non-object”的有关问题
-
Fatal error: Call to a member function fetch_array() on a non-object in 62 line
-
phpmyadmin出现了Fatal error: Call to a member function getName() 如何都打不开了
-
phpmyadmin出现了Fatal error: Call to a member function getName() 如何都打不开了