I have three files
1. space1.hpp 2. space2.hpp and 3. main.cpp
space1.hpp contains:
Code:
using namespace std;
namespace space1 {
class sp1{
public:
sp1(){
}
};
}
space2.hpp contain
Code:
#include "space1.hpp"
// want to use sp1 class here
using namespace std;
using namespace1;
namespace space2 {
class sp2{
public:
sp2(sp1 sp){
}
};
}
& main.cpp contains:
Code:
#include "space1.hpp"
#include "space2.hpp"
// want to use both the class sp1 and sp2 here
using namespace std;
using namespace space1;
using namespace space2;
int main(){
sp1 s1 =sp1();
sp2 s2 =sp2(s1);
}
Error is coming:
Code:
In file included from space2.hpp:1,
from main.cpp:2:
space1.hpp:4: error: redefinition of ‘class space1::sp1’
space1.hpp:4: error: previous definition of ‘class space1::sp1’
In file included from main.cpp:2:
space2.hpp:5: error: expected nested-name-specifier before ‘namespace1’
space2.hpp:5: error: ‘namespace1’ has not been declared
space2.hpp:11: error: expected ‘)’ before ‘sp’
main.cpp: In function ‘int main()’:
main.cpp:10: error: no matching function for call to ‘space2::sp2::sp2(space1::sp1&)’
space2.hpp:8: note: candidates are: space2::sp2::sp2()
space2.hpp:8: note: space2::sp2::sp2(const space2::sp2&)
kindly fix it!