class foo {
public:
static int func(const char*& p) const;
};
This is illegal, why?
Answer Posted / rohit
the 2nd const used in the example is invalid because it can
be used only with member functions which have a hidden
argument called this. The 2nd const would be applied to
this.
The funct is static member function so it hasn't any this
pointer.
Actually it is not obvious what is exactly inccorect.
We can remove static keyword, then we get syntactically
correct class definition, or we can remove 2nd const and
again the class can be considered valid.
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 ? | 0 Yes | 1 No |
Post New Answer View All Answers
What does stand for?
A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference
What is the use of the function in c?
What will be your course of action for a push operation?
What is the translation phases used in c language?
What are the types of operators in c?
How can I automatically locate a programs configuration files in the same directory as the executable?
my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?
stripos — Find position of first occurrence of a case- insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls.
Why main function is special give two reasons?
What are pointers in C? Give an example where to illustrate their significance.
Explain pointers in c programming?
Is there a way to switch on strings?
What do you mean by command line argument?
any C program contains only one function, it must be a) void () b) main () c) message () d) abc ()