静态成员函数 [英] static member function
本文介绍了静态成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我对结构有一个基本的疑问。
我有一个班级,其中我宣布了静态功能
class A
{
公开:
静态a;
静态f();
};
我可以在不创建
类A的实例的情况下访问静态函数。
我可以访问静态变量而不创建类的实例
A.
MJ
解决方案
MJ写道:
嗨
我对结构有一个基本的怀疑。
我有一个班级,我有一个声明静态功能
A级
{
公开:
静态a;
静态f();
};
>我是否可以在不创建类A实例的情况下访问静态函数。
我是否可以在不创建类实例的情况下访问静态变量
A.
MJ
http://cplus.about.com/od/beginnerct ... /aa080802a.htm
-
Alvin
MJ写道:< blockquote class =post_quotes>我对结构有一个基本的疑问。
我有一个课程,其中我已经宣布了一个静态的功能
A级公告:
br />静态a;
静态<什么类型?> a;
???
static f();
static<什么返回值类型?> f();
???
};
我是否可以在不创建实例的情况下访问静态函数
A类。
是。
我可以在不创建类实例的情况下访问静态变量
A。
是的。
V
MJ写道:嗨
我对结构有一个基本的疑问。
我有一个班级,其中我宣布了一个静态的功能
A级。
public:
static int a;
static float f(){return 3.14; }};
// in * .cpp
int A :: a = -1;
我可以访问静态函数吗没有创建一个类A的实例。
float g = A :: f();
我可以在没有的情况下访问静态变量创建一个
类A的实例。
int b = A :: a;
Abe
Hi
I have a basic doubt about structure.
I have a class in which a I have declared a static funtion
class A
{
public:
static a;
static f();
};
Can I access the the static function without creating a instance of a
class A.
Can I access the static variable without creating a instance of a class
A.
MJ
解决方案
MJ wrote:
Hi
I have a basic doubt about structure.
I have a class in which a I have declared a static funtion
class A
{
public:
static a;
static f();
};
Can I access the the static function without creating a instance of a
class A.
Can I access the static variable without creating a instance of a class
A.
MJ
http://cplus.about.com/od/beginnerct.../aa080802a.htm
--
Alvin
MJ wrote:I have a basic doubt about structure.
I have a class in which a I have declared a static funtion
class A
{
public:
static a;
static <what type?> a;
???
static f();
static <what return value type?> f();
???
};
Can I access the the static function without creating a instance of a
class A.
Yes.
Can I access the static variable without creating a instance of a class
A.
Yes.
V
MJ wrote:Hi
I have a basic doubt about structure.
I have a class in which a I have declared a static funtion
class A
{
public: static int a;
static float f() { return 3.14; } };
// in *.cpp
int A::a = -1;
Can I access the the static function without creating a instance of a
class A.
float g = A::f();
Can I access the static variable without creating a instance of a class A.
int b = A::a;
Abe
这篇关于静态成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文