由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++ static member method with default arguments
相关主题
c++ 是否也有class method??why use static function here?
gdb里怎么call member functionTest your C++ knowledge...
static如何作为函数?static function and static variable?
When are data members initialized? what about static data m有没有static return type和static as function arguement?
问个static member function的问题matlab: how to set defaul value for function arguments
[合集] 为什么 const member 不能是 static.will static/global var be initialized to 0 in C/C++
递归程序C++ question
java 为什么这么冗长???C++ cast 小结
相关话题的讨论汇总
话题: index话题: c++话题: static话题: method话题: member
进入Programming版参与讨论
1 (共1页)
f*z
发帖数: 421
1
大牛,同学们,请教,static member method 可不可用default argument?比如,
enum Index
{
INDEX_A = 0,
INDEX_B
};
class foo
{
public:
static void method1( int a, int b = Index::INDEX_A);
};
编译可以过,但有什么要注意的地方?
多谢!
m*********a
发帖数: 3299
2
你用的是那个版本的IDE,我用的是Code::Blocks
int b=Index::INDEX_A 或int b=Index.INDEX_A无法通过编译
只能用 int b=INDEX_A 或 Index b=INDEX_A;
太落后了。
而且enum 在C++是个class么?INDEX_A 的default value 是0,INDEX_B是1.

【在 f*z 的大作中提到】
: 大牛,同学们,请教,static member method 可不可用default argument?比如,
: enum Index
: {
: INDEX_A = 0,
: INDEX_B
: };
: class foo
: {
: public:
: static void method1( int a, int b = Index::INDEX_A);

p***o
发帖数: 1252
3
For C++98, put Index in class foo to avoid polluting the outer namespace.
For C++11, you can use enum class so Index::INDEX_A will compile.

【在 m*********a 的大作中提到】
: 你用的是那个版本的IDE,我用的是Code::Blocks
: int b=Index::INDEX_A 或int b=Index.INDEX_A无法通过编译
: 只能用 int b=INDEX_A 或 Index b=INDEX_A;
: 太落后了。
: 而且enum 在C++是个class么?INDEX_A 的default value 是0,INDEX_B是1.

m*********a
发帖数: 3299
4
好了,可以用了。Index::INDEX_A
但是还是没有办法用Index.INDEX_A,这个只能在Visual Studio用吗?

【在 p***o 的大作中提到】
: For C++98, put Index in class foo to avoid polluting the outer namespace.
: For C++11, you can use enum class so Index::INDEX_A will compile.

s*******8
发帖数: 12734
5
index.INDEX_A not C++, it is java or c#

【在 m*********a 的大作中提到】
: 好了,可以用了。Index::INDEX_A
: 但是还是没有办法用Index.INDEX_A,这个只能在Visual Studio用吗?

1 (共1页)
进入Programming版参与讨论
相关主题
C++ cast 小结问个static member function的问题
来几个C++测试题[合集] 为什么 const member 不能是 static.
C -- sample without replacement递归程序
问两个问题,C++java 为什么这么冗长???
c++ 是否也有class method??why use static function here?
gdb里怎么call member functionTest your C++ knowledge...
static如何作为函数?static function and static variable?
When are data members initialized? what about static data m有没有static return type和static as function arguement?
相关话题的讨论汇总
话题: index话题: c++话题: static话题: method话题: member