Jump to content
  • Advertisement
Sign in to follow this  
ToohrVyk

[c++] Expression templates, typename?

This topic is 3499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
Quote:
Original post by ToohrVyk
Holy cow, this is what I get for coding at night.

Hardcode instead of Hardcore.


Ah, the irony...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!