Untitled
unknown
c_cpp
4 years ago
1.5 kB
25
Indexable
#include <iostream> #include <memory> #include <thread> #include <vector> // What is extern? extern int externInt; namespace { struct Base { virtual void printOut(const std::shared_ptr<int>& inVal) { std::cout<<"Base: "<< *inVal <<std::endl; }; ~Base() {}; }; struct Child : public Base { Child(int inSize) : mSize{ inSize}, mPtr{ new int(mSize)} { } ~Child() { free(mPtr); } void printOut(const std::shared_ptr<int> inVal) { std::cout<<"Child: "<< *inVal <<std::endl; }; int* mPtr; int mSize; }; void makeFalse(bool inBool){ inBool = false; } } // namespace int main() { Child a(/*externInt*/ 5); Base newA = a; Child newNewA = a; a.printOut(std::make_shared<int>(5)); static_cast<Base*>(&a)->printOut(std::shared_ptr<int>(new int(6))); bool someBool{ true }; makeFalse(someBool); // Which branch will be executed and why? if (~someBool) { std::cout<<"True: "<<(float)(1/2)<<std::endl; } else { std::cout<<"False: "<<(float)1/2<<std::endl; } std::string hello{ "Hello " }; std::string world{" World!!!"}; std::thread t1([&hello, inWorld = std::move(world)]() { std::this_thread::sleep_for(std::chrono::seconds(1)); std::cout<<hello<<inWorld<<std::endl; }); t1.detach(); //std::this_thread::sleep_for(std::chrono::seconds(4)); std::cout<<hello<<world<<std::endl; }
Editor is loading...