default arguments for class member template function

H

Hicham Mouline

Hello,
I am debugging (vs2008) the following code:
I type the URL weirdly here because I think messages with URL are rejected:
h t t p : / / codepad . org / zy3WFbe7
Please ignore all spaces when you paste into ur browser

From user code, I call:

const Curve1D<Trait> curve(/* ctor arguments*/);
double y = curve.Get<Something, Linear1D>( x );

when I get in the implementation of the Get() member function, the e that is
supposed to be constructed
with Linear1D() default ctor, isn't properly set.

introspecting e shows that
mfPrimebegin=NaN
mfPrimeend= 7.737463760456e-317#DEN
mfboundary= 3.6492352064455326e-307while they should all be NaNThis is in
debug.
Is there a problem defining the Get function outside of its encapsulating
class?
especially that it is a template member function?

regards,
 
V

Victor Bazarov

Hicham said:
I am debugging (vs2008) the following code:
I type the URL weirdly here because I think messages with URL are rejected:
h t t p : / / codepad . org / zy3WFbe7
Please ignore all spaces when you paste into ur browser

Read the FAQ 5.8 please.

V
 
H

Hicham Mouline

Victor Bazarov said:
Read the FAQ 5.8 please.
Apologies. This compiles and I believe respects all items of 5.8:

vs2008 compile with default debug options - winxp sp3 32bit
The problem is described in the previous message:



#include <limits>
#include <boost/call_traits.hpp>

const double NaN = std::numeric_limits<double>::quiet_NaN();

template<typename CurveTraits>
class Curve1D
{
public:
typedef typename CurveTraits::xType xType;
typedef typename CurveTraits::fType fType;

template<typename Interp, typename Extrap>
fType Get(xType abscissa,
typename boost::call_traits<Interp>::param_type i =Interp(),
typename boost::call_traits<Extrap>::param_type e =Extrap() )
const;
};

template<typename CurveTraits>
template<typename Interp, typename Extrap>
typename CurveTraits::fType
Curve1D<CurveTraits>::Get(xType x,
typename boost::call_traits<Interp>::param_type i,
typename boost::call_traits<Extrap>::param_type e )
const
{
// when debugger reaches here, e is not constructed properly
}

class Linear1D {
public:
/// Constructor
Linear1D(double fPrimebegin=NaN, double fPrimeend=NaN, double
fboundary=NaN)
: mfPrimebegin(fPrimebegin), mfPrimeend(fPrimeend),
mfboundary(fboundary)
{}
private:
double mfPrimebegin;
double mfPrimeend;
double mfboundary;
};


struct Trait {
typedef double xType;
typedef double fType;
};

int main()
{
const Curve1D<Trait> curve = {};
double y = curve.Get<Linear1D, Linear1D>( 5.0 );

return 0;
}



Thanks,
 
H

Hicham Mouline

Hicham Mouline said:
Apologies. This compiles and I believe respects all items of 5.8:

vs2008 compile with default debug options - winxp sp3 32bit
The problem is described in the previous message:



#include <limits>
#include <boost/call_traits.hpp>

const double NaN = std::numeric_limits<double>::quiet_NaN();

template<typename CurveTraits>
class Curve1D
{
public:
typedef typename CurveTraits::xType xType;
typedef typename CurveTraits::fType fType;

template<typename Interp, typename Extrap>
fType Get(xType abscissa,
typename boost::call_traits<Interp>::param_type i =Interp(),
typename boost::call_traits<Extrap>::param_type e =Extrap() )
const;
};

template<typename CurveTraits>
template<typename Interp, typename Extrap>
typename CurveTraits::fType
Curve1D<CurveTraits>::Get(xType x,
typename boost::call_traits<Interp>::param_type i,
typename boost::call_traits<Extrap>::param_type e )
const
{
// when debugger reaches here, e is not constructed properly
}

class Linear1D {
public:
/// Constructor
Linear1D(double fPrimebegin=NaN, double fPrimeend=NaN, double
fboundary=NaN)
: mfPrimebegin(fPrimebegin), mfPrimeend(fPrimeend),
mfboundary(fboundary)
{}
private:
double mfPrimebegin;
double mfPrimeend;
double mfboundary;
};


struct Trait {
typedef double xType;
typedef double fType;
};

int main()
{
const Curve1D<Trait> curve = {};
double y = curve.Get<Linear1D, Linear1D>( 5.0 );

return 0;
}



Thanks,

I have checked that the problem happens with vs2008 on debug, but not with
gcc43/gdb also in debug.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top