| Author |
Message |
![]() ![]() ![]() ![]()
Rasputin
Moderator Username: Rasputin
Post Number: 7982 Registered: 02-2008
Rating:  Votes: 1 (Vote!) | | Posted on Friday, April 09, 2010 - 10:25 am: |
![]() ![]() ![]() ![]() ![]() |
$20 + $5 tip usual gaa. 2 to 3 times a week. Appudappudu food kooda intiki pack chesukuntey inko $6 r $7 extra. Usually three 23 Oz beers and one peg of Chivas GreatBong: The old Sachin radiated heat. The new Sachin gives light. But he still remains the sun |
![]() ![]() ![]() ![]()
Chiru_fan
Hero Username: Chiru_fan
Post Number: 12305 Registered: 04-2008 Posted From: 151.196.183.248
Rating: N/A Votes: 0 (Vote!) | | Posted on Friday, April 09, 2010 - 09:31 am: |
![]() ![]() ![]() ![]() ![]() |
Rasp mama....personal question.... nuvvu week days loo bar ki poothuntaavu kadaa... general gaa akkada yemi thaaguthaavu and yenni pegs and yentha karsu avuthundi! maree personal anukuntee answer cheyyaku! CHIRU - SACHIN - FEDERER |
![]() ![]() ![]() ![]()
Rasputin
Moderator Username: Rasputin
Post Number: 7979 Registered: 02-2008
Rating: N/A Votes: 0 (Vote!) | | Posted on Friday, April 09, 2010 - 09:22 am: |
![]() ![]() ![]() ![]() ![]() |
Thanks Webbugger, that was a good read. GreatBong: The old Sachin radiated heat. The new Sachin gives light. But he still remains the sun |
![]() ![]() ![]() ![]()
Webbugger
Junior Artist Username: Webbugger
Post Number: 791 Registered: 03-2008 Posted From: 67.175.242.40
Rating: N/A Votes: 0 (Vote!) | | Posted on Friday, April 09, 2010 - 12:26 am: |
![]() ![]() ![]() ![]() ![]() |
Rasputin:
This topic is lot discussed on the web ... better to avoid such cases ...virtual functions itself will slow down the process/application there is snippet here http://stackoverflow.com/questions/496440/c-virtual-function -from-constructor i tried on my linux box (g++) it didn't work for me |
![]() ![]() ![]() ![]()
Rasputin
Moderator Username: Rasputin
Post Number: 7977 Registered: 02-2008
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 11:23 pm: |
![]() ![]() ![]() ![]() ![]() |
Ippudu konchem burra pani cheyyatledu. Thank you all for the participation in this thread. Repu continue cheddaamu ee discussion. GreatBong: The old Sachin radiated heat. The new Sachin gives light. But he still remains the sun |
![]() ![]() ![]() ![]()
Dts
Junior Artist Username: Dts
Post Number: 656 Registered: 08-2009 Posted From: 188.40.51.71
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 09:45 pm: |
![]() ![]() ![]() ![]() ![]() |
Rasputin:Ikkada conflict ye ledu anukuntaa kada. d3 * vaadithe virtual function/dynamic binding concept ye ledu. But, I think it will work. But, practical gaa....manam veelu unnantha varaku base class pointers ye use chesthaamu, so that we can keep the code common as much as possible.
I don't know how C++ binds it. But in Java for non-static methods are overridden to exhibit the behaviour of the derived class. Whereas for static methods there no overriding, the derived class hides the method. I was curious to know if C++ is following Java's hiding concept. In which case the base constructor is a static one in C++. కోటిపల్లికి దారడిగి కొండపల్లికి వెళ్తున్నావేమిటి? ...మనసు మార్చుకున్నాను! DTS "The digital experience" |
![]() ![]() ![]() ![]()
Rasputin
Moderator Username: Rasputin
Post Number: 7967 Registered: 02-2008
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 09:44 pm: |
![]() ![]() ![]() ![]() ![]() |
Prince_786:That means, a derived class object should have ALL the functionality/attributes of base class. And, that means there should not be any compromising of the base class constructor.
I disagree on the ALL part. I should have the choice to selectively ignore/override certain aspects of the base class. Forcing something from the base class on the derived class is against the "CONCEPT" of OOPS. As Dts mentioned, it works in Java. I know it works in ActionScript. Trueleader says it works in Visual C++. I am a Java hater and a C++ fan. But, for the first time I am seeing some holes in C++. C++ is not a true OOP language. It was kinda forcibly thrusted upon C. GreatBong: The old Sachin radiated heat. The new Sachin gives light. But he still remains the sun |
![]() ![]() ![]() ![]()
Rasputin
Moderator Username: Rasputin
Post Number: 7966 Registered: 02-2008
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 09:39 pm: |
![]() ![]() ![]() ![]() ![]() |
Dts:d3 *d1 = new d3() output d1.f1()
Ikkada conflict ye ledu anukuntaa kada. d3 * vaadithe virtual function/dynamic binding concept ye ledu. But, I think it will work. But, practical gaa....manam veelu unnantha varaku base class pointers ye use chesthaamu, so that we can keep the code common as much as possible. GreatBong: The old Sachin radiated heat. The new Sachin gives light. But he still remains the sun |
![]() ![]() ![]() ![]()
Prince_786
Junior Artist Username: Prince_786
Post Number: 332 Registered: 02-2008 Posted From: 75.94.207.140
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 09:37 pm: |
![]() ![]() ![]() ![]() ![]() |
// Webbugger, I strongly disagree. // Rasp, I agree with Webugger. You should not call a virtual function from base class constructor. Remember: If D is derived from B, then you should see the relationship of an instance of D as " IS AN" instance of B . That means, a derived class object should have ALL the functionality/attributes of base class. And, that means there should not be any compromising of the base class constructor. Again, the key word is "IS A". |
![]() ![]() ![]() ![]()
Dts
Junior Artist Username: Dts
Post Number: 655 Registered: 08-2009 Posted From: 188.40.51.71
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 09:31 pm: |
![]() ![]() ![]() ![]() ![]() |
It Worked in Java. -------- public class Auto { public Auto() { getColor(); } public void getColor() { System.out.println(this.getClass().getName()+" is White"); } public static void main(String args[]) { Auto a = new Auto(); Auto t = new Toyota(); Auto n = new Nissan(); Auto m = new Mazda(); } } class Toyota extends Auto { } class Nissan extends Auto { } class Mazda extends Auto { public void getColor() { System.out.println(this.getClass().getName()+" is Red"); } } -------- Auto is White Toyota is White Nissan is White Mazda is Red --------------- I am not an expert in C/C++. I'd like to know in C++ whether it is Overriding or Hiding the function. Check the output of the following and see the difference B *b1 = new d3() output b1.f1() d3 *d1 = new d3() output d1.f1() if you get b1.f1() from Base and d1.f1() from inherited then it is hiding not overriding. కోటిపల్లికి దారడిగి కొండపల్లికి వెళ్తున్నావేమిటి? ...మనసు మార్చుకున్నాను! DTS "The digital experience" |
![]() ![]() ![]() ![]()
Maverick
Hero Username: Maverick
Post Number: 15120 Registered: 01-2008 Posted From: 192.146.101.71
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 06:07 pm: |
![]() ![]() ![]() ![]() ![]() |
Thanks true |
![]() ![]() ![]() ![]()
Trueleader
Comedian Username: Trueleader
Post Number: 1991 Registered: 09-2009 Posted From: 216.241.170.12
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 06:01 pm: |
![]() ![]() ![]() ![]() ![]() |
Rasputin:Trueleader, thanks. I will try that tomorrow
You are always welcome
Rasputin:Ok, done for the day. Inka Bar ki velley time ayyindi. Bye.
Have Fun......Enjoy!!!!! |
![]() ![]() ![]() ![]()
Rasputin
Moderator Username: Rasputin
Post Number: 7963 Registered: 02-2008
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 06:00 pm: |
![]() ![]() ![]() ![]() ![]() |
Webbugger, I strongly disagree. It seems like a limitation in cetain C++ compilers. But, any "true" OOPS language should support calling virtual functions from anywhere. Oka chinna example scenario isthaanu.... base class constructor has three lines of code........ : there are 10 derived classes from this base class.... : 9 of those 10, have no issues with the lines in the base class constructor.... : But, for 10th class I want to skip the 2nd line of the base class constructor. : Intuitively,.... : you move that line into a function called foo() in the base class constructor...make it virtual.... : override it in the derived class, by making a empty foo() function in the 10th derived class. : thats it done... : all other 9 dervied classes execute that line from foo() function in the base class : the 10th derived class will not. : because it is overriden. : the point is.... : I want a different execution path in the constructor of the base class, for a particular derived class. Ok, done for the day. Inka Bar ki velley time ayyindi. Bye. GreatBong: The old Sachin radiated heat. The new Sachin gives light. But he still remains the sun |
![]() ![]() ![]() ![]()
Trueleader
Comedian Username: Trueleader
Post Number: 1990 Registered: 09-2009 Posted From: 216.241.170.12
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 05:58 pm: |
![]() ![]() ![]() ![]() ![]() |
Maverick:inko doubt..alantappudu asala function peru f1 deniki..it can be anything like f2 kada?
asala derived class lo function peru F1 ani evakapothey.....matching peru tho automaticga basefunction ki vellipothunadhi dynamic binding lo base class nunchi derived class method call avuthunadhi. |
![]() ![]() ![]() ![]()
Rasputin
Moderator Username: Rasputin
Post Number: 7962 Registered: 02-2008
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 05:52 pm: |
![]() ![]() ![]() ![]() ![]() |
read it as "you can't access it from derived class". GreatBong: The old Sachin radiated heat. The new Sachin gives light. But he still remains the sun |
![]() ![]() ![]() ![]()
Webbugger
Junior Artist Username: Webbugger
Post Number: 790 Registered: 03-2008 Posted From: 164.54.210.16
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 05:52 pm: |
![]() ![]() ![]() ![]() ![]() |
Rasputin it won't work Never Call Virtual Functions during Construction or Destruction http://www.artima.com/cppsource/nevercall.html |
![]() ![]() ![]() ![]()
Trueleader
Comedian Username: Trueleader
Post Number: 1988 Registered: 09-2009 Posted From: 216.241.170.12
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 05:51 pm: |
![]() ![]() ![]() ![]() ![]() |
Maverick:kind of cheating the compiler..virtual undede signature derived class lo marchukovacchu ani kada..correctena?
No Maverick Virtual keyword base class lo vundali. Derived class lo method ni override cheseydapudu same signature "virtual" lekunda evali. Signature match avaka potey adi overloading avutundi, overriding kadu |
![]() ![]() ![]() ![]()
Maverick
Hero Username: Maverick
Post Number: 15119 Registered: 01-2008 Posted From: 192.146.101.71
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 05:51 pm: |
![]() ![]() ![]() ![]() ![]() |
Trueleader:"virtual" keyword vunda kudadu.
inko doubt..alantappudu asala function peru f1 deniki..it can be anything like f2 kada? |
![]() ![]() ![]() ![]()
Rasputin
Moderator Username: Rasputin
Post Number: 7961 Registered: 02-2008
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 05:47 pm: |
![]() ![]() ![]() ![]() ![]() |
Trueleader, thanks. I will try that tomorrow. But, what if I have another level of inheritance. For example, if I derive a class E1 from D3 and override the f1() again. For this, I need to make it virtual in d3. Just food for brain kinda stuff. I will try this tomorrow. While I was looking up this stuff...I actually came across another good topic "using private virtual functions". First thing that came to my mind was, what is the purpose of making a private function virtual, you can "access" it from the derived class anyways. Then I realized, you can still override it in the derived class. So, even if it is called from the base class, it will do as defined in the derived class. GreatBong: The old Sachin radiated heat. The new Sachin gives light. But he still remains the sun |
![]() ![]() ![]() ![]()
Maverick
Hero Username: Maverick
Post Number: 15117 Registered: 01-2008 Posted From: 192.146.101.71
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 05:40 pm: |
![]() ![]() ![]() ![]() ![]() |
Trueleader:Endukante Derived class lo overriding method signature base class ki match avali and derived class lo "virtual" keyword vunda kudadu.
kind of cheating the compiler..virtual undede signature derived class lo marchukovacchu ani kada..correctena? |
![]() ![]() ![]() ![]()
Maverick
Hero Username: Maverick
Post Number: 15116 Registered: 01-2008 Posted From: 192.146.101.71
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 05:36 pm: |
![]() ![]() ![]() ![]() ![]() |
Trueleader: iste work chestundi. Endukante Derived class lo overriding method signature base class ki match avali and derived class lo "virtual" keyword vunda kudadu.
work ayyinda cool..i told the reverse of it.. |
![]() ![]() ![]() ![]()
Maverick
Hero Username: Maverick
Post Number: 15115 Registered: 01-2008 Posted From: 192.146.101.71
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 05:35 pm: |
![]() ![]() ![]() ![]() ![]() |
Rasputin:Base class constructor in Visual C++?
.NET ani uddesam like java |
![]() ![]() ![]() ![]()
Trueleader
Comedian Username: Trueleader
Post Number: 1987 Registered: 09-2009 Posted From: 216.241.170.12
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 05:34 pm: |
![]() ![]() ![]() ![]() ![]() |
Rasputin:
just tested this in VC++.Net 2008, It worked fine. Replace this Class d3 : public B { virtual f1( ) { //d3 specific code } } with this one..... Class d3 : public B { void f1( ) { //d3 specific code } } iste work chestundi. Endukante Derived class lo overriding method signature base class ki match avali and derived class lo "virtual" keyword vunda kudadu. |
![]() ![]() ![]() ![]()
Rasputin
Moderator Username: Rasputin
Post Number: 7960 Registered: 02-2008
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 05:30 pm: |
![]() ![]() ![]() ![]() ![]() |
Ye version antey eti cheppedi. Ikkada maa Linux box lo vachina edo g++ compiler. But, our resident C++ expert here says, it won't work in any C++ compiler due to some v-tables issue. Trueleader, are you saying that I can override a function which is being called from Base class constructor in Visual C++? GreatBong: The old Sachin radiated heat. The new Sachin gives light. But he still remains the sun |
![]() ![]() ![]() ![]()
Trueleader
Comedian Username: Trueleader
Post Number: 1986 Registered: 09-2009 Posted From: 216.241.170.12
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 05:01 pm: |
![]() ![]() ![]() ![]() ![]() |
Rasputin:
Visual C++.Net aithe correct gane pani chestundi. Question lo meeru aa version of C++ vaduthunaro cheppa ledu. |
![]() ![]() ![]() ![]()
Maverick
Hero Username: Maverick
Post Number: 15113 Registered: 01-2008 Posted From: 192.146.101.71
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 04:34 pm: |
![]() ![]() ![]() ![]() ![]() |
Sachin:
expert emi kaadu..anduke tappu cheppa..c++ chesi long time ayyindi..ilanti threads lo kasta knowledge dorukutundani |
![]() ![]() ![]() ![]()
Sachin
Hero Username: Sachin
Post Number: 14628 Registered: 04-2008 Posted From: 24.187.205.230
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 04:32 pm: |
![]() ![]() ![]() ![]() ![]() |
Maverick:
annai endi nuvvu....oracle nate vasthavu..unix ante vasthe .. OBI ante vasthaaavu...ippudu C+ .....enni vachu saaami neeeku |
![]() ![]() ![]() ![]()
Rasputin
Moderator Username: Rasputin
Post Number: 7959 Registered: 02-2008
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 04:31 pm: |
![]() ![]() ![]() ![]() ![]() |
Base class lo virtual ga declare cheyyakunda, akkadi nundi call chesthe eppudoo base class version exectute avuthundi kada (if the reference pointer is of Base Class type). Virtual vaadedey anduku. It seems to work fine from everywhere else in the base class except the Constructor. Adi ikkada problem. GreatBong: The old Sachin radiated heat. The new Sachin gives light. But he still remains the sun |
![]() ![]() ![]() ![]()
Maverick
Hero Username: Maverick
Post Number: 15112 Registered: 01-2008 Posted From: 192.146.101.71
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 04:30 pm: |
![]() ![]() ![]() ![]() ![]() |
sorry..i was wrong |
![]() ![]() ![]() ![]()
Maverick
Hero Username: Maverick
Post Number: 15111 Registered: 01-2008 Posted From: 192.146.101.71
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 04:29 pm: |
![]() ![]() ![]() ![]() ![]() |
Rasputin:virtual void f1( ) { //d1 ,d2 and base use this code
} ikkada virtual vadakunda normal static binding vadilesi kinda virtual vadite dynamic binding at run time tho call avutundemo?? |
![]() ![]() ![]() ![]()
Rasputin
Moderator Username: Rasputin
Post Number: 7957 Registered: 02-2008
Rating: N/A Votes: 0 (Vote!) | | Posted on Thursday, April 08, 2010 - 04:18 pm: |
![]() ![]() ![]() ![]() ![]() |
I noticed that something actually works better in ActionScript than in C++ (surprise, surprise!!!) Scenario: I have a base class B and this has a virtual function f1( ) and d1, d2 and d3 are the derived classes of the B. Only d3 overrides the virtual function. Question : from my B constructor i need to call the function f1( ). For the objects of type d1 and d2 i expect the base class versions virtual function be called, but for the objects of d3 i am expecting the d3 version of the virtual function to be executed. Class B { public: B( ) { f1( ); } virtual void f1( ) { //d1 ,d2 and base use this code} } Class d1 : public B { } Class d2 : public B { } Class d3 : public B { virtual f1( ) { //d3 specific code } } main( ) { B *b1 = new d1( ); /*base version of the f1() would be called */ B *b3 = new d3( ); /*I expect the derived version of the f1() would be called, but base version of f1() is called instead. */ } In ActionScript, all functions are virtual. and I see d3's f1() function called. But, in C++ I see B's f1() function being called. Is there anyway I can change the code to make C++ work the same way like ActionScript? I am almost certain that even Java would behave like ActionScript here. Bottomline: How to override a function called in the base class of a constructor? GreatBong: The old Sachin radiated heat. The new Sachin gives light. But he still remains the sun |