CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Interview Success Kit - Get Success in Job Interviews Interview Success Kit - 30,000 Interview Que. & Ans.
Covers 30,000+ Interview Questions asked in actual MNC Interviews - all with model answers.
Get Your Dream Job Now - www.vyoms.com
Sponsored Links
Interview Questions
Our Services

INTERVIEW QUESTIONS C++ OPERATORS IN C++ DETAILS
Question :
Why can't we overload the sizeof, :?, :: ., .* operators in c++?


Category Operators in C++ Interview Questions
Rating (3.5) By 97 users
Added on 8/18/2011
Views 6009
Rate it!
Answers:

The restriction is for safety.For example if we overload . operator then we cant access member in normal way for that we have to use ->.



I think the above answer is not appropriate .<br><br>According to me all these operators use name instead of operand ,so we can`t pass any name (either of variable,class) to any function . We must have to pass the operand for that .



Posted by: Ankur Bamby

Contact Ankur Bamby Contact Ankur Bamby

Nice answer, but it does not suite for :? operator as it does not take name as parameter.<br>BTW, the reason we cannot overload :? is that it takes 3 argument rather than 2 or 1. There is no mechanism available by which we can pass 3 parameter during operator overloading.<br>For other operators, the previous ans is enough.



Posted by: Tapesh Maheshwari

Contact Tapesh Maheshwari Contact Tapesh Maheshwari

In any languages all operator has some precedence, due to precedence they work.like +,-,() all have some precedence, as we know operator overloading work differently without changing the specific meaning of the operator and in this case :,?:, etc. have no predefined precedence.And if we want to overload these operator then compiler does not understand and conflicts, and generates an error.



Posted by: jitendra singh

Contact jitendra singh Contact jitendra singh

According to Bjarne Stroustrup, the operators ., .* ,:?, :: & sizeof() cannot be overloaded as they take name as their argument whereas all other operators take value as argument.<br><br>Class A<br>{<br>public:<br> int i;<br>};<br><br>A a,b,c;<br><br>Eg: c = a+b - both a & b actually refer to some memory location, so "+" operator can be overloaded, but the "." operator, like a.i actually refers to the name of the variable from whom the memory location has to be resolved at time and thus it cannot be overloaded.<br><br><br>



Posted by: Sunil Paduchuru

Contact Sunil Paduchuru Contact Sunil Paduchuru

Most operators can be overloaded by a programmer. The exceptions are<br><br> . (dot) :: ?: sizeof<br><br>There is no fundamental reason to disallow overloading of ?:. I just didn't see the need to introduce the special case of overloading a ternary operator. Note that a function overloading expr1?expr2:expr3 would not be able to guarantee that only one of expr2 and expr3 was executed.<br><br>Sizeof cannot be overloaded because built-in operations, such as incrementing a pointer into an array implicitly depends on it. Consider:<br><br> X a[10];<br> X* p = &a[3];<br> X* q = &a[3];<br> p++; // p points to a[4]<br> // thus the integer value of p must be<br> // sizeof(X) larger than the integer value of q<br><br>Thus, sizeof(X) could not be given a new and different meaning by the programmer without violating basic language rules.<br><br>In N::m neither N nor m are expressions with values; N and m are names known to the compiler and :: performs a (compile time) scope resolution rather than an expression evaluation. One could imagine allowing overloading of x::y where x is an object rather than a namespace or a class, but that would - contrary to first appearances - involve introducing new syntax (to allow expr::expr). It is not obvious what benefits such a complication would bring.<br><br>Operator . (dot) could in principle be overloaded using the same technique as used for ->. However, doing so can lead to questions about whether an operation is meant for the object overloading . or an object referred to by . For example:<br><br> class Y {<br> public:<br> void f();<br> // ...<br> };<br><br> class X { // assume that you can overload .<br> Y* p;<br> Y& operator.() { return *p; }<br> void f();<br> // ...<br> };<br><br> void g(X& x)<br> {<br> x.f(); // X::f or Y::f or error?<br> }<br><br>This problem can be solved in several ways. At the time of standardization, it was not obvious which way would be best. For more details, see D&E.



Posted by: Hitesh

Contact Hitesh Contact Hitesh

these type of operator don't there own value,but in overloading not change there own value while overloading that's why if there don't have any value how this is possible to overload..



Posted by: pratik arya

Contact pratik arya Contact pratik arya

these operators are not used in other meanigful restriction<br>for example + used in addition and sign that operators are used in<br>numerical calculation depends on precedence



Posted by: pon babitha

Contact pon babitha Contact pon babitha

(.)dot operators cann't use in operator overloading because dot is predifined for software programe,with out dot we cann't acess namespase,calling of an object,inheretance.so if we use as overloading it may confuse to the software programe



Posted by: sridhar

Contact sridhar Contact sridhar

If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
  • Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification Enter the above shown code: *
    Inform me about updated answers to this question

    Related Questions
    View Answer
    What is a scope resolution operator?


    View Answer
    Can you explain the term "resource acquisition is initialization?"

    View Answer
    What is the difference between operator new and the new operator?

    View Answer
    Difference between a "assignment operator" and a "copy constructor"

    View Answer
    Define copy constructor? What is the use of copy constructor?

    View Answer
    In C++, what is a constructor,destructor?
    View Answer
    Can you declare the override method static while the original method is non-static?
    View Answer
    How can you overload a method?
    View Answer
    What is a scope resolution operator?
    View Answer
    Difference between realloc() and free()?
    View Answer

    Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

    View ALL Operators in C++ Interview Questions & Answers

    User Options
    Latest 20 Questions
    What are the characteristics of services?
    What are services?
    What are refunds?
    What do you mean by product complement?
    What are the Components of Financial Market?
    What is rebate?
    What are the functions of Financial Market?
    What are contests?
    What are sweepstakes?
    State the methods of sales promotion.
    What do you mean by sales promotion?
    What are the moral qualities of a good salesman?
    what are the social qualities of a good salesman?
    What are the mental and psychological qualities of a good salesman.
    What are the physical qualities of a good salesman?
    State the difference between advertising and promotion.
    State the features of personal selling.
    What are the essentials of advertisement copy?
    What is advertisement copy?
    What are the merits and demerits of advertising?



    Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

    Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

    Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

    MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
    MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

    GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

    IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
    IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

    SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
    SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |




    Copyright ©2003-2016 CoolInterview.com, All Rights Reserved.
    Privacy Policy | Terms and Conditions



    Cache = 0 Seconds