A:static成员变量在对象构造时候生成
B: static成员函数在对象成员函数中无法调用
C: 虚成员函数不可能是static成员函数
D: static成员函数不能访问static成员变量
答案:c 解释,(1)类的static成员变量属于该抽象类,需要在类定义时初始化,不可以在对象的构造函数中初始化。(2) static成员函数在对象成员函数中可以调用,同属于一个类作用域 (3)正确,static成员函数不可以声明为const和virtual,详见C++ primer (4)static成员函数只能够访问static 成员变量。
#ifndef TEST_H
#define TEST_H
#include <stdio.h>
class test
{
private:
int submember;
static int member;
public:
static void writetest(int member)
{
test::member = member;
// test::submember = member;
}
static void display(int count)//static成员函数,属于抽象类,不属于类对象
{
printf("the count number is %d \n",count);
}
void readtest(int mem) //对象成员函数
{
printf("helllo %d \n",test::submember);
// test::writetest(mem);// static成员函数在对象成员函数中可以调用,同属于一个类作用域,但是,static函数不能包含对stati成员的操作,否则出现错误
display(8);
}
};
#endif
#include "onceon.h"
int main(void)
{
int aa = 2;
test a ;
a.readtest(aa);
}