How to place classes in separate files (C++) -
i'm having difficulties placing class separate file , calling in main
. below simple code.
wondering how can use getkey()
function int main()
#include "stdafx.h" #include <iostream> #include <string> #include "travelfunctions.h" using namespace std; travelfunctions::getkey() { cout << "i bananna" << endl; }
my travelfunction.h
class
class travelfunctions { public: getkey(); }
my main class
#include "stdafx.h" #include <iostream> #include <string> #include "travelfunctions.h" using namespace std; int main() { getkey bo; return 0; }
you have first instance object class. main function should this:
int main() { travelfunctions functions; functions.getkey(); return 0; }
you should define void return type of function.
.cpp:
void travelfunctions::getkey() { cout << "i bananna" << endl; }
.h:
class travelfunctions { public: void getkey(); }; // notice have add ; after class definition
Comments
Post a Comment