非静态和静态数据和函数 [英] non-static and static data and functions

查看:87
本文介绍了非静态和静态数据和函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在静态成员函数中调用非静态数据成员吗?
还可以在静态成员函数中调用非静态成员函数?

Is it possible to call a non-static data member in a static member function? And is it also possible to call a non-static member function in a static member function?

如何做?

推荐答案

是 - 您可以这样做

class Foo
{
    public:
     static void staticFunc( const Foo &  foo)
     {
           foo.memberFunc();      

     }
      void memberFunc() const
      {
           staticFunc(*this);

      } 


};

这是一种设计,递归,演示如何调用静态和非静态成员函数。

This is the sort of a design, recursion aside, demonstrates how to call both static and non-static member functions.

这篇关于非静态和静态数据和函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆