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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -