Are function calls allowed to default initialize a construction parameter? Does the compiler turn the function into a constant? How does that work? I wasn't aware you could do this...

On Dec 11, 2007 8:02 PM, Stjepan Rajko < stipe@asu.edu> wrote:
On Dec 11, 2007 1:03 PM, Robert Dailey < rcdailey@gmail.com> wrote:
>
> template< typename T >
>  struct default_alpha;
>
> template<>
> struct default_alpha<float>
> {
>     static const float value = 1.0f; // Note that this is not legal. I'm
> simply just presenting pseudo code.
>
> };
>
> template<>
> struct default_alpha<unsigned char>
> {
>     static const unsigned char value = 255;
> };
>
>
> template< typename T >
> class Color
> {
>     Color( T r, T g, T b, T a = default_alpha<T>::value );
> };
>

So why not use Jeff Flinn's suggestion:

template< typename T >
struct default_alpha;

template<>
struct default_alpha<float>
{
   static float value() { return 1.0f; }
};

template<>
struct default_alpha<unsigned char>
{
   static unsigned char value() { return 255; }
};

template< typename T >
class Color
{
public:
   Color( T r, T g, T b, T a = default_alpha<T>::value() );
};


...?

Stjepan
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users