///////////////////////////////////////////////////////////////////////////////// // PointersAndReferences.cpp - demonstrates basic types and references // // // // Jim Fawcett, Summer Short Course, Su2016 // ///////////////////////////////////////////////////////////////////////////////// /* * Found in: Handouts\ShortCourse\Repository\GettingStartedExamples * */ #include #include #include "Utilities.h" class Hello { public: void say() { std::cout << "\n hello world"; } }; struct Test { int i = 5; double d = 3.141592; Hello h; std::string s = "a string"; }; using namespace Utilities; int main() { title("Demonstrating variables, pointers, and C++ references", '='); putLine(); title("using struct directly"); Test test; std::cout << "\n " << test.i << ", " << test.d << ", " << test.s; test.h.say(); putLine(); title("using pointer to struct"); Test* pTest = &test; std::cout << "\n " << pTest->i << ", " << pTest->d << ", " << pTest->s; pTest->h.say(); putLine(); title("using reference to struct"); Test& rTest = test; std::cout << "\n " << rTest.i << ", " << rTest.d << ", " << rTest.s; rTest.h.say(); putLine(); putLine(); }