views:

96

answers:

1

I want to forward declare:

namespace boost {
    namespace property_tree {
        template<typename Key, typename Data, typename KeyCompare = std::less<Key> >
        class basic_ptree;
        typedef basic_ptree< std::string, std::string > ptree;
    }
}

but my g++ cribs about redefinition due to default template argument. How can I achieve this?

+5  A: 

To forward-declare the property_tree, you should include the

#include <boost/property_tree/ptree_fwd.hpp>

header, instead of declaring one yourself.

KennyTM
The point about a forward declaration is that you do not want to include the header.
Job
@Job: Wrong. The point about [forward declaration](http://en.wikipedia.org/wiki/Forward_declaration) is *not giving the complete definition of the whole structure*, to allow forward reference.
KennyTM
... when a header is called `..._fwd.hpp`
David Rodríguez - dribeas
@KennyTM: Sure, that's what I meant. I agree I didn't make it very clear:-) Also, I didn't notice the `_fwd.hpp`. Does Boost make special headers for forward declarations?
Job
@Job: Yes. Because the how the stuffs are defined are often unspecified, the only safe way is to include the `_fwd` header.
KennyTM
Kenny, Thanks for your reply. But thats not what I wanted. I have a header file which has a reference to ptree but I didn't want to include boost header files in this file as this would make all other code which includes this header will have to include boost. I wanted to forward declare the boost dependencies and remove the boost inclusion.Anyway I've found out a way.
kumar