Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What does stand for?

1051


A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference

1057


What is the use of the function in c?

981


What will be your course of action for a push operation?

1063


What is the translation phases used in c language?

1074


What are the types of operators in c?

1016


How can I automatically locate a programs configuration files in the same directory as the executable?

1117


my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?

1542


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.

2413


Why main function is special give two reasons?

1499


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

1177


Explain pointers in c programming?

1071


Is there a way to switch on strings?

1036


What do you mean by command line argument?

1111


any C program contains only one function, it must be a) void () b) main () c) message () d) abc ()

1090