class foo {
public:
static int func(const char*& p) const;
};

This is illegal, why?

Answer Posted / abdur rab

A member function can be declard as Const by considering
the fact that they contain a hidden "this pointer" to be a
pointer to a const object. However Static methods do not
have the "this pointer", and hence can't be const or
virtual.

Hence it is illegal to declare a static function as const.

The C++ language standard stipulates at section 9.4.1
that "[...] A static
member function shall not be declared const

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a stream water?

656


what are the advantages of a macro over a function?

647


What is the difference between a free-standing and a hosted environment?

640


what are non standard function in c

1436


Who is the main contributor in designing the c language after dennis ritchie?

553






Write a program to check prime number in c programming?

597


What happens if you free a pointer twice?

610


What is the difference between %d and %i?

596


What is a method in c?

628


Can an array be an Ivalue?

666


What is a null pointer assignment error? What are bus errors, memory faults, and core dumps?

905


What is the difference between near, far and huge pointers?

628


Explain the difference between #include "..." And #include <...> In c?

632


Tell me what are bitwise shift operators?

658


How do I convert a string to all upper or lower case?

629