Boost logo

Boost Users :

Subject: Re: [Boost-users] Library Developers Battling Cyclic Header Dependency
From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2011-03-16 15:16:04


From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Ryan

On Wed, Mar 16, 2011 at 2:18 PM, Simonson, Lucanus J <lucanus.j.simonson_at_[hidden]> wrote:

> > In the boost library system I coundn't find any .cpp files that would indecate a compilable library.

 
> Any idea where the compilable files are in the boost library?
 
All the code compiles. If you mean cpp files, then it is true, many libraries are header file only and don't need to be compiled seperate from the project code that uses them. Just include the headers to use them.
 

> assuming A.hpp is included first,

 
> Is there a way to make the classes able to not care about which class is included first?

 
//File A.hpp
class B;
 
class A {
  double x;
public:
  B inline convertToB(void);
};
 
//File B.hpp
class A;
 
class B {
  double y;
public:
  A inline convertToA(void);
  }
};

//File AB_details.hpp
B A::convertToB(void) {
  return B(x);
}

A B::convertToA(void) {
  return A(y);
}
 
A.hpp and B.hpp can be included in any order, but AB_details needs to be included after both and before convertToA() or convertToB() is used.
 
> >You also need to declare the functions inline to prevent multiple definition link errors since the classes and their member functions are not templated.

 
> If the entire class is in a header doesn't this removed the need for the inline call?

No, inline keyword is required for the function to be made a weak symbol in the object file. Definition in a header file does not by itself make a weak symbol. To the compiler and linker code is code regardless of whether it is in a file with .hpp or .cpp. We also have the extern keyword to provide information to the linker about what our intentions are.
 
Regards,
Luke


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net