Implicit pointer conversion

Hello,

Say we have a Derived pointer. A function takes a Base pointer.
Can I do this?
1
2
3
4
5
6
void test(Base* ptr)
{

}
Derived* obj;
test(obj);


I don't have access to a compiler here so I cant test it out :)
Nvm I found an online C++ interpreter and it works :)
FWIW, this is one of the fundamentals of polymorphism (so, a function that takes a 'Shape *' can take a 'Square *' if Square derives from Shape). You can also see similar behavior with references

1
2
3
4
5
6
void test(Base & input)
{

}
Derived obj;
test(obj);
Topic archived. No new replies allowed.