Boost logo

Boost Users :

From: Frank (opcode_at_[hidden])
Date: 2005-11-03 19:39:12


I have the following code ( very simplified but compilable)

// =========== start snip ===============================

/// ======= in hpp ============
#include <boost/static_assert.hpp>
template <typename T, unsigned short DIM=3>
class Vector
{
public:
    Vector(void)
        {/*init code omitted*/}
    Vector(const Vector& v)
        {/* ctor code omitted */}

    //=====================================================
    // some ctors for small DIM's
    // will cause compile time errors if DIM != # of args
    //=====================================================
#ifdef enable_small_dim_ctor
    explicit Vector( T x )
        {
        BOOST_STATIC_ASSERT(DIM==1);
        data_[0]=x;
        }

    Vector( T x, T y )
        {
        BOOST_STATIC_ASSERT(DIM==2);
        data_[0]=x; data_[1]=y;
        }

    Vector( T x, T y, T z )
        {
        BOOST_STATIC_ASSERT(DIM==3);
        data_[0]=x; data_[1]=y; data_[2]=z;
        }
#endif

private:
    T data_[DIM];
};

template <typename T>
class Vector3 : public Vector<T,3>
{
public:
    Vector3(){};
    Vector3 Normal() const;
};

//==================== in cpp =================

// provide implementation of Normal
template <typename T>
Vector3<T> Vector3<T>::Normal() const
{
    Vector3 n;
    return n;
}

// explicit instantiation of the normal method
#ifdef try_export

// causes error STATIC_ASSERTION_FAILURE
template class __declspec(dllexport) Vector3<double>
Vector3<double>::Normal() const;

#else

//OK
template class Vector3<double> Vector3<double>::Normal() const;

#endif

// ============== end snip ===============================

I 'm trying to put the implementation into a dll and mark the explicit
instantiation of Normal as exported with the following results:
1) With the small_dim_ctor's enabled I get the static assertion when marked
for export
2) With the small_dim_ctor's enabled everything is ok when not marked for
export
3) With the small_dim_ctor's disabled everything is ok regardless of export
marking
4) If I comment out the BOOST_STATIC_ASSERT and build my app with export
enabled I can use the resulting dll without any problems

I'm thinking that marking for export is somewhow generating an implicit
conversion somewhere but I don't know how.

Using VStudio .Net 2003.

Any help is appreciated.

Thanks
Frank


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