How to specify namespace of a library?

Please help me with namespace.
Here is a simplified example of what I am trying to do:

There are two static C++ libraries named lib1 and lib2.
lib1 and lib2 are similar and contain the same class names, but the corresponding lib2 classes have more functionality.
lib2 classes inherit from lib1 classes of the same name.
This is what I am trying to do with made up syntax:

lib1::classA.h
1
2
3
4
class classA
{
	void fn1();
};


lib2::classA.h
1
2
3
4
5
#include <lib2::classA>
class classA: public lib2::classA
{
	void fn2();
};


What is the correct syntax for specifying namespace of the lib2 library?

Thank you.
If the header files have the same name, place them in different sub-directories.

header lib1/classA.h
1
2
3
4
5
6
7
8
9
// #include guard

namespace lib1
{
     class classA
     {
          // ...
     };
}


header lib2/classA.h
1
2
3
4
5
6
7
8
9
10
11
// #include guard

#include <lib1/classA.h>

namespace lib2
{
     class classA : public lib1::classA
     {
          // ...
     };
}
Thanks JLBorges. But I am getting I compile error I can not figure out:
A.h:8:18: error: 'lib1' has not been declared


lib_namespace/lib1/A.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#ifndef A_h
#define A_h

#include <iostream>

namespace lib1
{
	class A
	{
		public:
			virtual void fn();
	};
}
#endif 


lib_namespace/lib1/A.cpp
1
2
3
4
5
6
#include "A.h"

void lib1::A::fn()
{
	std::cout << " lib1::A::fn()";
}


lib_namespace/lib2/A.h
1
2
3
4
5
6
7
8
9
10
11
12
13
#ifndef A_h
#define A_h

#include <iostream>

#include "../lib1/A.h"

class A : public lib1::A  //error: 'lib1' has not been declared
{
	public:
		virtual void fn();
};
#endif 


lib_namespace/lib2/A.cpp
1
2
3
4
5
6
#include "A.h"

void A::fn()
{
	std::cout << " lib2::A::fn()";
}


output:
C:\demo_MinGW\lib_namespace\lib2>g++ A.cpp
In file included from A.cpp:1:0:
A.h:8:18: error: 'lib1' has not been declared
 class A : public lib1::A
                  ^
A.h:8:24: error: expected '{' before 'A'
 class A : public lib1::A
                        ^
A.h:9:1: error: invalid type in declaration before '{' token
 {
 ^
A.h:9:1: warning: extended initializer lists only available with -std=c++11 or -
std=gnu++11 [enabled by default]
A.h:10:2: error: expected primary-expression before 'public'
  public:
  ^
A.h:10:2: error: expected '}' before 'public'
A.h:10:2: error: expected ',' or ';' before 'public'
A.h:12:1: error: expected declaration before '}' token
 };
 ^
You have duplicated #include guards. #ifndef A_h

Instead, something like: #ifndef LIB1_A_h // lib1 and #ifndef LIB2_A_h // lib2
Thank you JLBorges! That worked.
Topic archived. No new replies allowed.