File: Test.cpp
Headerfile:Code:#include <iostream> using namespace std; Test() { name = "Abc"; cout << name; }
My MainCode:#ifndef TEST_H #define TEST_H class Test { protected: char* name; public: Test(); }; #include "..\Test.cpp" //Path is correct #endif
If I put everything in one file (one header) it works, to then include this into the main.cpp:Code:#include <iostream> #include "..\HeaderFiles\Test.h" //Path is correct. int main() { cout << "Hello World"; // :D Test t = new Test(); return 0; }
Code:#ifndef GREN_H #define GREN_H class Test { protected: char* name; public: Test(); }; Test::Test() { } #endif
Edit:
I got this to work! But:
Why can I not do it the way I want to: putting the .cpp file into the header, instead of putting the header into the .cpp file. Am I doing something wrong, or this cannot be done depending on the compiler ("Thats how the compiler is built")?
Writing the top then import the bottom, or writing the bottom to later import the top, should not make a difference?
I find this way more logical for me, so really wanna pull this off!![]()



LinkBack URL
About LinkBacks



