Skip to content

Instantly share code, notes, and snippets.

@brschettini
Created September 25, 2023 17:57
Show Gist options
  • Save brschettini/f95d11d161c8c62e857a37df0a5e3752 to your computer and use it in GitHub Desktop.
Save brschettini/f95d11d161c8c62e857a37df0a5e3752 to your computer and use it in GitHub Desktop.
Final code for RASC training
#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