![]() |
|
#1
|
|||
|
|||
Question related to Operator overloadingi want to know the use about declaring a constructor as explicit??
what are its advantages or disadvantages?? |
|||
|
#2
|
|||
|
|||
Re: Question related to Operator overloadingSorry the subject of this topic may be misleading i read this in operator overloading:
Code is here: CPP / C++ / C Code: CPP / C++ / C Code:
Now i has 3 observation regarding this code. 1. This code works perfectly with or without keyword explicit. Now if i change a statement dist3 = dist1 + dist2; to dist3 = dist1 + 12.25; Code stops work .But if initialize 2 argument constr as Distance(int ft, float in=0.0) : feet(ft), inches(in) { } This code works. 2.Using explicit keyword makes the code stop compiling.That ok. 3.when i am not using 'explicit', conversion are happening but results are not as desired, because of possible initialization of inches always to 0.0. So what is use of keyword explicit?? Last edited by admin : 09-Jun-2008 at 04:12.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|
#3
|
|||||
|
|||||
Re: Question related to Operator overloadingQuote:
Quote:
CPP / C++ / C Code:
Quote:
CPP / C++ / C Code:
Quote:
Quote:
|
|
#4
|
|||
|
|||
Re: Question related to Operator overloadingyes i forget to remove that line:
Distance dist5=11.35; Yet keyword explicit practical usability remains mystery for me. |
|
#5
|
|||
|
|||
Re: Question related to Operator overloadingQuote:
CPP / C++ / C Code:
Declaring a constructor an explicit will disallow implicit conversions. Implicit conversions are subtle & they frequently bite people. explicit is an attempt to control this particular problem. |
|
#6
|
|||
|
|||
Re: Question related to Operator overloadingThanks dear!!
|
|
#7
|
|||
|
|||
Re: Question related to Operator overloadingYou need to use keywords explicit to force explicit conversion operator.
Explicit constructor only allow to accept one argument. Danny is my GURU. I hope this help. |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Question about locking surfaces to directly access pixels, SDL. | george89 | C++ Forum | 0 | 18-Jun-2006 22:16 |
| Question re "Similar Pages" on Google | jep | Search Engine Optimization Forum | 0 | 17-May-2005 10:52 |
| C++ Syntax Highlighter related question | JdS | GIDForums™ | 4 | 25-Oct-2004 09:00 |
| question of practice | magiccreative | C++ Forum | 1 | 06-Feb-2004 08:17 |
| 'Related articles' php /mysql question | JdS | MySQL / PHP Forum | 4 | 06-Sep-2002 11:17 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The