不允许使用static const函数? [英] static const function not allowed?
问题描述
我有类似的东西
//
// common.h
const unsigned long m_dwStyle = 0x123;
//
// common.h
static BOOL风格(DWORD dw)const
{
return((m_dwStyle& dw)== dw);
};
//
//
但我的编译器告诉我静态成员函数不允许使用修饰符。
但我看不出上面有什么问题。
Simon
Simon写道:< blockquote class =post_quotes>
我有类似
// common.h
静态BOOL样式(DWORD dw)const
{
返回((m_dwStyle& dw)== dw);
};
但我的编译器告诉我静态成员函数上不允许使用修饰符。
但我看不出上面有什么问题。
我怀疑这个功能是defi在一个班级里面或者错误
可能会有所不同。 const是指const。修改只允许在
非静态成员函数上。想一想:const成员函数不是允许修改它所调用的对象的
,但是静态成员
函数不会在对象上调用。拥有一个const静态成员
函数是没有意义的,因此它是非法的。
Jonathan
Simon写道:
我有类似的东西
//
// common.h
const unsigned long m_dwStyle = 0x123;
// common.h
static BOOL Style(DWORD dw)const
返回((m_dwStyle& ; dw)== dw);
};
//
//
但我的编译器告诉我静态成员函数上不允许使用修饰符。
但是我看不出上面有什么问题。
静态成员是类的成员,而不是类的实例,所以
它不能是常数,因为没有一个对象是const ... ...
-
Ian Collins。
" Ian Collins" < IA ****** @ hotmail.com>在消息中写道
news:4c ************* @ individual.net ...
但是我的编译器告诉我静态成员
函数上不允许使用修饰符。
但是我看不出上面有什么问题。
一个静态成员是类的成员,而不是类的实例,所以
它不能是const,因为没有一个对象是const ... ...
我明白了,
那么'首选定义是什么?
BOOL样式(DWORD dw) const;
//或
静态BOOL样式(DWORD dw);
问候,
>
Simon
Hi,
I have something like
//
// common.h
const unsigned long m_dwStyle = 0x123;
//
// common.h
static BOOL Style( DWORD dw )const
{
return ((m_dwStyle&dw)==dw);
};
//
//
But my compiler tells me "modifiers not allowed on static member functions".
But I cannot see what is wrong with the above.
Simon
Simon wrote:Hi,
I have something like
// common.h
static BOOL Style( DWORD dw )const
{
return ((m_dwStyle&dw)==dw);
};
But my compiler tells me "modifiers not allowed on static member functions".
But I cannot see what is wrong with the above.
I suspect the function is defined inside a class or else the error
would probably be different. The "const" modified is only allowed on
non-static member functions. Think: a const member function is not
allowed to modify the object it is called on, but static member
functions are not called on an object. Having a const static member
function makes no sense, hence it is illegal.
Jonathan
Simon wrote:Hi,
I have something like
//
// common.h
const unsigned long m_dwStyle = 0x123;
//
// common.h
static BOOL Style( DWORD dw )const
{
return ((m_dwStyle&dw)==dw);
};
//
//
But my compiler tells me "modifiers not allowed on static member functions".
But I cannot see what is wrong with the above.
A static member is a member of the class, not an instance of a class, so
it can''t be const as there isn''t an object to be const with...
--
Ian Collins.
"Ian Collins" <ia******@hotmail.com> wrote in message
news:4c*************@individual.net...
But my compiler tells me "modifiers not allowed on static member
functions".
But I cannot see what is wrong with the above.
A static member is a member of the class, not an instance of a class, so
it can''t be const as there isn''t an object to be const with...
I see,
so what would be the ''preferred definition?
BOOL Style( DWORD dw )const;
// or
static BOOL Style( DWORD dw );
Regards,
Simon
这篇关于不允许使用static const函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!