Boost logo

Boost Users :

Subject: [Boost-users] BOOST_STATIC_CONST
From: Olivier Tournaire (olitour_at_[hidden])
Date: 2010-03-12 17:03:59


Hi all,

I am currently having problem with a static const class member (in a header
only project):

// type.hpp
template< typename Property >
struct property_base
{
    typedef Property type;
};

struct some_type : property_base< uint32_t >
{
    BOOST_STATIC_CONSTANT( type, first_value = 1 );
    BOOST_STATIC_CONSTANT( type, second_value = 2 );
};

// main.cpp
#include "type.hpp"
...
int main(int argc, char** argv)
{
   BOOST_CHECK_EQUAL( 1 , some_type::first_value );
}

This produces a link error (g++ 4.3.4): undefined reference to
some_type::first_value. Everything is fine with visual ...

If I add const some_type::type some_type::first_value; after the struct
definition, it compiles and links fine. However, would it produce a multiple
definition link error in some cases?
Could you please help?

Regards,

Olivier



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