Reputation: 141
I am pretty new to the concept of splitting a program into header
and etc. Normally, it goes ok, but in this case I have a whole bunch of errors if i try to do next:
Suppose I have a .cpp file:
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include "Header.h"
using namespace std;
int main() {
//some code here
}
map <char, char> create(vector <char> &one, vector <char> &two) {
//some code here
}
vector <char> conc(string phrase) {
// some code here
}
vector <char> result(vector<char> three, map <char, char> code) {
// some code here
}
In Header.h
I have:
map <char, char> create(vector <char> &one, vector <char> &two);
vector <char> conc(string phrase);
vector <char> result(vector<char> three, map <char, char> code);
Which are just function declarations.. If I put them in .cpp the program works great, but if in Header.h - it does not. Could you, please tell what I am missing here?
I am reading about the concept of splitting on cprogramming.com, but they never had an example with STL. Thank you!
Upvotes: 0
Views: 127
Reputation: 1976
You use using namespace std;
in cpp file, but not in header (and don't use it in header), so you should use fully qualified type names:
#ifndef HEADER_H
#define HEADER_H
#include <string>
#include <map>
#include <vector>
std::map <char, char> create(std::vector <char> &one, std::vector <char> &two);
std::vector <char> conc(std::string phrase);
std::vector <char> result(std::vector<char> three, std::map <char, char> code);
#endif // HEADER_H
Upvotes: 5
Reputation: 3530
This is mostly an educated guess since you didn't post the actual error nor the whole code.
You're missing std::
before every STL class name since you should not use using
statement in header files.
Example:
std::map <char, char> create(std::vector <char> &one, std::vector <char> &two);
Also make sure you have the proper include statement at the top of your header file (<vector>
, etc...).
Upvotes: 2