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
1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their children’s names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. 2) the Event Manager has to send participants to the stage to perform in the order in which they registered. Write a program that will help the Event Manager know who to call to the stage to perform. The Logic should be in Data Structures
Can an array be an Ivalue?
Lists the benefits of c programming language?
Write a program in c to replace any vowel in a string with z?
When should we use pointers in a c program?
What are the advantages of c preprocessor?
Explain what are bus errors, memory faults, and core dumps?
is it possible to create your own header files?
What is the difference between text and binary i/o?
Why c is called a middle level language?
main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }
What is 2 d array in c?
What is %g in c?
what is event driven software and what is procedural driven software?
what is the function of pragma directive in c?