Default template function objects

Discussion in 'C++' started by Rune Allnor, Dec 3, 2011.

  1. Rune Allnor

    Rune Allnor Guest

    Hi all.

    I am trying to implement a class for numerical work.
    Prt of the functionality will be an accumulator, that is,
    a scalar variable x that scales general data y on
    the form (declarations below)

    T x;
    U y;

    y*=x;

    The type T is either a double or a float, whereas
    the type U might be any numerical data type
    (double, float, complex<>, vector, matrix,...).

    I would like to set this up with default template
    declarations so that if, say, T = U = double,
    then double::eek:perator*=(const double&) is invoked
    by default.

    I have attempted to set this up in terms of template
    declarations, as several variations of this idea:

    #include <boost/bind.hpp>

    template<
    class T,
    class U = T,
    class AccT = boost::bind(&operator+=,_1) // <<========
    >

    class MyClass{
    public:
    private:
    };

    However, no matter what I try, I can't get the compiler
    to accept the indicated line. Either there is a type argument
    missing, or there is some other error.

    So the question is if I am on th eright track, with only a detail
    wrong, or if this is a blind alley with no hope of success?

    Rune
    Rune Allnor, Dec 3, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Allan Schwartz
    Replies:
    1
    Views:
    395
    Victor Bazarov
    Aug 9, 2004
  2. Jim West
    Replies:
    3
    Views:
    756
    Jim West
    Oct 7, 2004
  3. Vijai Kalyan
    Replies:
    4
    Views:
    701
    Vijai Kalyan
    Nov 8, 2005
  4. 7stud
    Replies:
    11
    Views:
    683
    Dennis Lee Bieber
    Mar 20, 2007
  5. Peng Yu
    Replies:
    3
    Views:
    767
    Thomas J. Gritzan
    Oct 26, 2008
Loading...

Share This Page