how can I divide the header and implementation of a global function?
My way is:
split.h
#pragma once #include <string> #include <vector> #include <functional> #include <iostream> void split(const string s, const string c); split.cpp
#include "split.h" void split(const string& s, const string& c){ ... } main.cpp
// main.cpp : Defines the entry point for the console application. // #include <string> #include <vector> #include <functional> #include <iostream> #include "stdafx.h" #include "split.h" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { vector<string> v; string s = "The;;woraaald;;is;;not;;enoaaaugh"; string c = " aaa ;; ccc"; split(s,c); return 0; } And errors are:
Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ...\split.h 8
Error 2 error C2146: syntax error : missing ',' before identifier 's' ...\split.h 8
How can I solve this problem? thx
std::namespace. Do not useusing namespacein the header file, fully qualify the name. For consistency, perhaps try to rid yourself of that habit in source files as well.stringwhich needs to bestd::string(unless you specifyusing std::string;).