我如何...为以下描述编写程序 [英] How do i...write the program for this below description
问题描述
编写一个程序来设计一个具有名为show count()的静态成员函数的类,该函数具有显示该类创建的对象数的属性
我尝试过:
编写一个程序来设计一个名为show count()的静态成员函数的类它具有显示类创建的对象数的属性
Write a Program to design a class having static member function named show count () which has the property of displaying the number of objects created of the class
What I have tried:
Write a Program to design a class having static member function named show count () which has the property of displaying the number of objects created of the class
推荐答案
Classes(I) - C ++ Tutorials [ ^ ]
只是一个提示:您可以覆盖类的默认构造函数,以便您可以增加静态成员变量,从而实现所请求的功能。
定义了默认构造函数的类的示例,以及静态成员变量:
Just a tip: you can override the default constructor of the class so that you can increment the static member variable, achieving the requested functionality.
Example of a class with default constructor defined, as well as a static member variable:
/* Here is the class definition */
class MyClass
{
public:
/* Here is a parameterless constructor */
MyClass() {
/* Code of the constructor goes here */
}
private:
/* Here is a static member variable definition */
static int count;
};
除此之外,你的任务非常简单;如果您不理解某些技术术语,您应该向您的老师询问。例如,对于我们大多数人来说静态成员变量是非常自我解释的,但是如果你不理解它,你应该回到基础并学习所有这些技术术语。
Apart from that, your assignment is pretty straightforward; if you do not understand some of technical terms, you should ask to your teacher. For example, for the most of us a static member variable is pretty self explanatory, but if you do not understand it you should get back to the basis and learn all those technical terms.
这篇关于我如何...为以下描述编写程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!