Sign in to follow this  
ToohrVyk

[c++] Expression templates, typename?

Recommended Posts

ToohrVyk    1596
Every once in a while, I get stumped on a C++ concept (usually templates). I'm writing an expression template framework where I construct classes inheriting from hardcode<N,T>::output by wrapping them in hardcode<N,T>::wrapper<X> and defining the correct operators. Here is a minimal example:
template <typename N, typename T>
struct hardcode
{
  class output 
  {
  public:
    typedef N name_type;
    typedef T value_type;
    virtual ~output() {}
  };
  
  template<typename A, typename B>
  class seq : public output
  {
    A left;
    B right;
  public: 
    seq(const A &left, const B &right) : 
      left(left), right(right) {}
  };
};

template <typename N, typename T, typename A, typename B>
typename hardcode<N,T>::template wrapper< typename hardcode<N,T>::template seq<A,B> > 
operator >> 
( const typename hardcode<N,T>::template wrapper< A > &a, 
  const typename hardcode<N,T>::template wrapper< B > &b) 
{
  return typename hardcode<N,T>::template wrapper< typename hardcode<N,T>::template seq<A,B> >
    (typename hardcore<N,T>::template seq<A,B>(a.value,b.value)); // Line 30
}


This example defines a way of constructing a "seq" sequence object using operator>>. The problem is that, well, it doesn't work:
test.cpp: In function ‘typename hardcode<N, T>::wrapper<typename hardcode<N, T>::seq<A, B> > operator>>(const typename hardcode<N, T>::wrapper<A>&, const typename hardcode<N, T>::wrapper<b>&)’:
test.cpp:30: error: expected nested-name-specifier before ‘hardcore’
test.cpp:30: error: expected `(' before ‘hardcore’
test.cpp:30: error: expected primary-expression before ‘>’ token
test.cpp:30: error: expected id-expression before ‘template’
test.cpp:30: error: expected primary-expression before ‘>’ token
I have no idea why the typename qualifier breaks precisely on that line.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this