Header-Handling C++ - not the expected Output! Handling 3 Files ... [SOLVED]
Hi there! Got 3 files: TestClass.h TestClass.cpp CallingTestClass.cpp TestClass.h: sample Class declared in this Header-file. #ifndef TESTCLASS_H #define TESTCLASS_H #include <string> using namespace std; class TestClass{ public: TestClass(){} string aString; int aInt; void setSum(int a); private: void privateMethod(); int privateSum; }; #endif TestClass.cpp: defining the methods and so on in the sourcefile #include "TestClass.h" #include <iostream> TestClass::TestClass() { aString = "Hi there!"; }; void TestClass::setSum(int a ){ privateSum = a; }; CallingTestClass: creating a obj of the TestClass (Constructor is called and sets the string var to "Hi there!" - then Output this string ... but nothing appears! Seems like the defined constructor of TestClass.cpp isnt called! MS does it the same way, by defining a sample method ... https://docs.microsoft.com/en-us/cpp/cpp/header-files-cpp?view=vs-2019 #include <iostream> #include "TestClass.h" using namespace std; int main(int argc, char* argv[]){ TestClass* objOne = new TestClass(); cout << objOne->aString; return 0; }