c++ - How can I use functions in another .cpp file? -
i making project in visual studio 2013 preview includes code tutorials learning c++ from. main file in project contains program able launch functions defined in .cpp file in same project. code below:
#include "stdafx.h" #include <iostream> #include "comments.cpp" #include "structure of program.cpp" int structure(void); void comment(void); int main() { using namespace std; cout << "this project contains files related chapter 1 of learn cpp tutorials\n" << endl; cout << "please type in tutorial number view output:\n" << "1 - structure of program\n" << "2 - comments\n" << "3 - first @ variables (and cin)\n" << "4 - first @ functions\n" << "5 - first @ operators\n" << "6 - whitespace & basic formatting\n" << "7 - forward declarations\n" << "8 - programs multiple files\n" << "9 - header files\n" << "10 - first @ preprocessor\n" << "11 - how design first programs\n" << endl; int x; cin >> x; if (x == 1) { structure(); } if (x == 2) { comment(); } cout << "thank using program. bye." << endl; return 0; }
the problem having when build program, there error saying functions launching defined though not so. basically, need in how launch functions located in different .cpp file in same project.
thanks
never include .cpp files!
typically, including .cpp file result in recompilation of code should not or may not compiled several times (hence link errors). on other hand, in .h files put declarations , other stuff may compiled several times, compiled once every include of .h file.
in case, since have declared structure() , comment() don't need replace .cpp includes anything.
Comments
Post a Comment