Here is the code
Code:
//vector.h
int add(int x, int y);
//vector.cc
#include <iostream>
int add(int x, int y){
return (x+y);
}
int main(){
std::cout<<add(1,1)<<std::endl;
return 0;
}
Obviously I do NOT need to include vector.h to compile. However, when I use namespace:
Code:
//vector.h
namespace TEST{
int add(int x, int y);
}
//vector.cc
#include <iostream>
#include "vector.h"
int TEST::add(int x, int y){
return (x+y);
}
int main(){
std::cout<<TEST::add(1,1)<<std::endl;
return 0;
}
I have to include "vector.h" otherwise compiler complains:
Code:
> g++ -o vec vector.cc
vector.cc:5: error: syntax error before `::' token
vector.cc: In function `int main()':
vector.cc:10: error: `TEST' undeclared (first use this function)
vector.cc:10: error: (Each undeclared identifier is reported only once for each
function it appears in.)
vector.cc:10: error: parse error before `::' token
Anybody knows why is that?