cant i invoke both simultaneously?? if i try to make two objects like x const a; x a; then it gives error..can u explain plz.
On Jul 12, 9:55 pm, Sandeep Jain <sandeep6...@gmail.com> wrote: > *const* in C++ is not exactly same as *final* in java. SO unlike java adding > the keyword const to a function does not affect overriding. > Infact, adding in C++ const functions ==> that they will not modify any > member of the class. > non-const functions cannot be invoked by const objects. > > Try making object 'a' as const i.e. > const x a; > and then invoke f(), it should invoke the correct version. > > Note that C++ allows function overloading based on const-ness. > Refer (Const function > section)http://www.cprogramming.com/tutorial/const_correctness.html > Also, subscript operators generally come in pairs, > Referhttp://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-1...http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.12 > > Regards, > Sandeep Jain > > On Tue, Jul 12, 2011 at 10:09 PM, dheeraj tyagi <dheeraj2...@gmail.com>wrote: > > > > > > > > > const means that it cannot be overloaded..i think due to that this is > > happening. > > > On Tue, Jul 12, 2011 at 9:26 PM, segfault <pawan1991ya...@gmail.com>wrote: > > >> #include<iostream> > >> using namespace std; > >> class x{ > >> public: > >> x() {} > > >> int func() const{ > >> cout<<"it is const function\n"; > >> } > > >> int func() { > >> cout<<"it is simple functin\n"; > >> } > > >> }; > >> int main() > >> { > >> x a; > >> a.func(); > >> return 0; > >> } > > >> why cann't it take const function? > >> explain it > > >> -- > >> You received this message because you are subscribed to the Google Groups > >> "Algorithm Geeks" group. > >> To post to this group, send email to algogeeks@googlegroups.com. > >> To unsubscribe from this group, send email to > >> algogeeks+unsubscr...@googlegroups.com. > >> For more options, visit this group at > >>http://groups.google.com/group/algogeeks?hl=en. > > > -- > > With regards > > Dheeraj Tyagi > > 8197218001 > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To post to this group, send email to algogeeks@googlegroups.com. > > To unsubscribe from this group, send email to > > algogeeks+unsubscr...@googlegroups.com. > > For more options, visit this group at > >http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.