Reflections on a written question

Source: Internet
Author: User

The following statement is wrong (C)

A, the static member function does not have this pointer.
B, the static member function cannot directly access a non-static member.
C, static data members cannot be initialized in the definition body of a class.
D, static data members exist independent of any object of the class and are not part of the object of that class type.

Analyze a option

A static member function does not have the this pointer because it is not associated with any object. In this sense, it cannot access non-static data members that belong to a class object, nor can it access a non-static member function, which only calls the rest of the static member functions.

b option
//the following class definitions, The following is a static member function that accesses a non-static function directly error  class  base     {static  void  fun_static (); static    void  fun_non_static (); }; void  base :: Fun_static () {fun_non_static ();}  
//如下的类定义,static成员函数可以通过对象间接访问非static函数classbase{     staticvoid fun_static(base &a);    staticvoid fun_non_static();   };voidbase::fun_static(B){        B.fun_non_static();}
C option
class  base  { static  const  int  i=0 ;    //Yes, but the data member must still be defined outside the definition body of the class  static  int  j=0 ;    //can not   static  int  m;    //can be  const  int  count;    //can be  const    int  count=0  //can };

It is also said that a very mass data member cannot be initialized in the class definition body, and constant is possible.

d option

Non-static data members exist in each object of the class type, unlike normal data members, where static data members exist independent of any object of the class, and each static data member is an object associated with the class. is not associated with the object of the class.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Reflections on a written question

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.