如果类没有被创建,则没有对应的成员,也就无法访问
下面这种方法需要先创建类,并将类作为参数传递给静态成员函数才能访问。
阅读(193) | 评论(0) | 转发(0) |
<script>window._bd_share_config={"common":{"bdsnskey":{},"bdtext":"","bdmini":"2","bdminilist":false,"bdpic":"","bdstyle":"0","bdsize":"16"},"share":{}};with(document)0[(getelementsbytagname('head')[0]||body).appendchild(createelement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new date()/36e5)];</script>
下面这种方法需要先创建类,并将类作为参数传递给静态成员函数才能访问。
- #include <iostream>
- using namespace std;
-
-
- class person {
- public:
- virtual void get_name()=0;
- };
-
-
- class student:public person
- {
- public:
- void get_name()
- {
- cout <<"student name"<<endl;
- }
- static void get_age(student *_s);
- student();
- private:
- int m_age;
- };
-
- student::student()
- {
- m_age = 11;
- }
-
- void student::get_age(student *_s)
- {
- cout <<"student age: "<<_s->m_age<<endl;
- }
-
- student *create_person()
- {
- return new student();
- }
-
- int main()
- {
- student *p = create_person();
- p->get_name();
- student::get_age(p);
- return 0;
- }
相关热门文章
给主人留下些什么吧!~~
评论热议