Problems with "Barton Nackman Trick"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Lehn

    #1

    Problems with "Barton Nackman Trick"

    I want to use the "Barton Nackman trick" for my matrix hierarchy. But I ran
    into a problem with a typedef I need in the base class:

    template <typename E>
    class Matrix
    {
    public:
    typedef typename E::TT TT;

    };

    template <typename T>
    class DenseMatrix : public Matrix<DenseMat rix<T> >
    {
    public:
    typedef T TT;

    };

    this gives the error: no type named `TT' in `class DenseMatrix<dou ble>'

    Is there a chance to solve this problem, or is it even a comipler problem?

    I think the approach is pretty useless if this doesn't work. Most (or even
    all) methods in the base class will depend on the parameter "E::TT".

  • Michael Lehn

    #2
    Re: Problems with &quot;Barton Nackman Trick&quot;

    Michael Lehn wrote:
    [color=blue]
    > I want to use the "Barton Nackman trick" for my matrix hierarchy. But I
    > ran into a problem with a typedef I need in the base class:
    >
    > template <typename E>
    > class Matrix
    > {
    > public:
    > typedef typename E::TT TT;
    >
    > };
    >
    > template <typename T>
    > class DenseMatrix : public Matrix<DenseMat rix<T> >
    > {
    > public:
    > typedef T TT;
    >
    > };
    >
    > this gives the error: no type named `TT' in `class DenseMatrix<dou ble>'
    >
    > Is there a chance to solve this problem, or is it even a comipler problem?
    >
    > I think the approach is pretty useless if this doesn't work. Most (or
    > even all) methods in the base class will depend on the parameter "E::TT".[/color]

    hmmm, this seems to work:

    template <typename A>
    struct Traits
    {
    };

    template <typename E>
    class Matrix
    {
    public:
    typedef typename Traits<E>::TT TT;

    };

    template <typename T>
    class DenseMatrix : public Matrix<DenseMat rix<T> >
    {
    public:
    typedef T TT;

    };

    template <typename T>
    struct Traits<DenseMat rix<T> >
    {
    typedef T TT;
    };


    ....is this a bug or a feature?

    Comment

    • Michael Lehn

      #3
      Re: Problems with &quot;Barton Nackman Trick&quot;

      So is this standard conform?

      Comment

      Working...