Skip to content

Instantly share code, notes, and snippets.

@kioba
Created August 30, 2016 14:49
Show Gist options
  • Save kioba/8a13e4db72528674c775e3e2ab58e22c to your computer and use it in GitHub Desktop.
Save kioba/8a13e4db72528674c775e3e2ab58e22c to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <memory>
class Base
{
public:
virtual void print() {
printf("Base");
}
};
class Derived :
public Base
{
public:
virtual void print() override {
printf("Derived");
}
};
int main()
{
//todo lessons
std::shared_ptr<Derived> der{ new Derived };
std::weak_ptr<Base> base = std::dynamic_pointer_cast<Base>(der);
if (auto lock = base.lock()) {
lock->print();
} else {
printf("could not lock");
}
char a[256];
scanf_s("%s", a, 256);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment