Anonymous
But it can be not one
Anonymous
But that's what I'm asking why ?
Because destructor is not in virtual table of a class
Anonymous
TO create object we need complete information.But, while we are using virtual, we do not have vptr and vtable at the point of object creation
Anonymous
We need to know the exact type of the object when we are creating object.
Anonymous
You said "Because destructor is not in virtual table of a class". Yes, it is not then what?
Anonymous
Anonymous
We need to know the exact type of the object when we are creating object.
I understand that we do not know the exact type of the object but how is it related to constructor not being virtual.
Anonymous
destructor
Anonymous
If we don't know the exact type then we can call only methods in which we 100% sure, right? Base* can refer as to a Base object as to a Derived one
Anonymous
I will explain it here.
Anonymous
wait
Anonymous
I understand that we do not know the exact type of the object but how is it related to constructor not being virtual.
when you use virtual, that virtual function needs to pointed by vptr. but vptr and vtable are only available after object creation.
Anonymous
constructor deals with object creation thus it can't be virtual
Anonymous
cause you should know the exact type of object while creating
Anonymous
Whenever we have base *b = new Derived(); then if we call any non-virtual function as b->fun(), then at compile time it will run the fun() of base class due to compile time poly. Same is the case with destructor as well If we make fun() as virtual then it will run the child class fun() due to RUN-time poly. So, we need to make destructor is virtual so that first the child class destructor is executed first. Is it completely correct Or do I need to add more. KINDLY REPLY!!
Anonymous
I GUESS COMPILE TIME POLYMORPHISM = EARLY BINDING. Isn't it?
Anonymous
no (stop the caps)
Now this is something new. give some reference.
Anonymous
I mean early binding happens in compile time poly.
olli
https://en.cppreference.com/w/cpp/language/virtual
Anonymous
Nowhere did they specify early binding in the article.
olli
early binding = direct function call = not polymorphic late binding = (runtime) polymorphic How much do you know about CS?
Anonymous
I meant early binding happens in compile time poly
Anonymous
so what is an example of compile time poly without direct function call?
olli
I meant early binding happens in compile time poly
define "compile time poly"
olli
Neither any academia I trust nor the standard define this term
Thor
Guys,, Is there any online website to check our knowledge about c/c++?
Thor
Thanks❤️
Anonymous
doesn't a simple call to non-virtual function fall under compile-time polymorphism
Anonymous
?
olli
doesn't a simple call to non-virtual function fall under compile-time polymorphism
What's polymorphic about that? struct X { void foo() {} }; int main() { X x{}; x.foo(); }
Anonymous
yeah it shouldn't be polymorphic. I accept my Bad. overloading should be compile time poly
olli
define "polymorphism"
Anonymous
having different forms of a thing.
Pietrø
Can anyone suggest me a good IDE for Mac?
Anonymous
Can anyone suggest me a good IDE for Mac?
Combination of Sublime text and terminal is best in my view.
Pietrø
Combination of Sublime text and terminal is best in my view.
I already use sublime text but I'm not really confident with the terminal
Pietrø
When I Had windows I used dev c++
Anonymous
I already use sublime text but I'm not really confident with the terminal
You just need to use change directory and compilation and code execution and nothing else
Pietrø
Basically I have to go to the directory of the file, and then?
Anonymous
use : g++ filename.cpp
Anonymous
to compile
Anonymous
and to run use ./a.out
Pietrø
g++ is used for compiling right?
Pietrø
I mean, it is the command
Anonymous
yep
Anonymous
yeah
olli
In a nutshell Polymorphism is the Ability of type A to appear as and be used like another type B
Pietrø
and to run use ./a.out
./a.out and then? No file name?
Anonymous
./a.out and then? No file name?
just ./a.out and nothing else
Pietrø
What if I have many files?
olli
yes
so how does it apply to overloading?
Anonymous
so how does it apply to overloading?
I meant that overloading is compile time polymorphism and I accept that it was my mistake to say that calling a non-virtual function is compile time polymorphism. My bad.
Anonymous
In overloading you use different functions with same name and different parameter types to do some specific job.
olli
struct X { void foo(int) {} void foo() {} }; int main() { X x{}; x.foo(3); } Do I use x different when I call foo or foo(3) ? Does any of these call make it pretend to be something else?
Anonymous
So same function name but different param type to do different jobs
Anonymous
No you don't use x differently.
olli
so it's not poylmorphic
Anonymous
I thought if we have different functions with same name but different param types or different no. of param types then
Anonymous
these we would be following function overloading.
olli
yes, function overloading, but not polymorphism
olli
these are two different things
olli
in C++ you can actually achieve "Static" or Compile time polymorphism by using CRTP. e.g. template <class D> struct Base { void foo() { static_cast<D*>(this)->foo(); } }; struct X : Base<X> { void foo() {} };
Anonymous
I'm yet to learn about static casting and templates. I won't understand it now.