Boost logo

Boost :

From: boost (boost_at_[hidden])
Date: 2001-05-04 07:21:49


Salut,

On Thursday 03 May 2001 08:44, you wrote:
> With your helpful question (answered with a further question below at end)
> I am nearer to a solution, though not necessarily an efficient one.
>
> Paul
[...]
> template<class T>T constants<T>::pi = (T)3.1459L; // works BUT
>
> need to instantiate as
>
> constants<const double>::pi;
>
> rather than <double> - or you can alter it!
[..]
> Agreed. But I found you can then alter it!!!! pi = 999.;
>

constants<const double> is actually more accurate for constants :)

But I can't reproduce your problem,
see appended example.

Best wishes
Peter
--------------------------------------------------------
#include <iostream>

template<typename T>
class Q
{
public:
        static const T zz;
};

template<>
const int Q<int>::zz = 17;

template<>
const double Q<double>::zz = 42;

int main()
{
        Q<double> q;

        q.zz = 34;

        std::cout << "int: " << q.zz << std::endl;
        return 0;
}


--------------------
Configuration: MSVC_Test - Win32 Debug
Compiling...
t1.cpp
V:\NRG++\MSVC_Test\t1.cpp(20) : error C2166: l-value specifies const object
Error executing cl.exe.

MSVC_Test.exe - 1 error(s), 0 warning(s)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk