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 the value of c?

576


What are compound statements?

633


What is a file descriptor in c?

568


How the c program is executed?

638


What are pointers in C? Give an example where to illustrate their significance.

754






What is a spanning Tree?

966


What is wrong with this program statement? void = 10;

828


What is this pointer in c plus plus?

600


int i=10; printf("%d %d %d", i, i=20, i);

1018


The statement, int(*x[]) () what does in indicate?

649


What is wrong with this declaration?

615


What is the ANSI C Standard?

782


What are the 4 data types?

604


What is variable initialization and why is it important?

623


What are terms in math?

597