-
-
Save brschettini/f95d11d161c8c62e857a37df0a5e3752 to your computer and use it in GitHub Desktop.
Final code for RASC training
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
#include <string> | |
#include <vector> | |
#include <memory> | |
class ExampleNode { | |
public: | |
ExampleNode(const std::string& name) { | |
this->node_name_ = name; | |
std::cout << "Node Created!" << std::endl; | |
} | |
~ExampleNode() { | |
std::cout << "Node destroyed!" << std::endl; | |
} | |
std::string getNodeName() { | |
return node_name_; | |
} | |
private: | |
std::string node_name_; | |
}; | |
int main() { | |
std::shared_ptr<ExampleNode> node_ptr; | |
node_ptr = std::make_shared<ExampleNode>("example_node"); | |
std::cout << "The node_name_ accessed by -> is: " << node_ptr->getNodeName() << std::endl; | |
std::cout << "The memory address allocated is: " << node_ptr.get() << std::endl; | |
auto another_node_ptr = std::make_shared<ExampleNode>("other example_node"); | |
std::cout << "The node_name_ accessed by -> is: " << another_node_ptr->getNodeName() << std::endl; | |
std::cout << "The memory address allocated is: " << another_node_ptr.get() << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment