Reputation: 764
I'm trying to create typedef
of a vector class I have. I have found similar problems on SO, but they focus on classes that are templates that accept different types of data, while my class is template based on integers.
So, my class is defined like this:
namespace sc_dt {
template <int W> class sc_bv { ... }; //meaning systemc_bit_vector
}
And I want to use typedef so I wouldn't have to type in sc_dt::
every time. However, by using this:
typedef sc_dt::sc_bv<int> sc_vector;
I get the following error:
Type/value mismatch at argument 1 in template argument list
How do I fix this?
Upvotes: 0
Views: 914
Reputation: 180990
namespace sc_dt {
template <int W> class sc_bv { ... } //meaning systemc_bit_vector
}
Has a non-type template parameter. When you instantiate an object of sc_bv
you need to give it an int
constant like
sc_dt::sc_bv<2> foo;
As you can see that is different than
typedef sc_dt::sc_bv<int> sc_vector;
Where you gave it a type, instead of a value.
If you know what value you want to use for sc_vector
then you could use
typedef sc_dt::sc_bv<the_value_that_you_want_to_use> sc_vector;
or if you just want sc_vector
to be a new name for the class template then you can use an alias template like
template<int value>
using sc_vector = sc_dt::sc_bv<value>;
which then lets you use sc_vector
like
sc_vector<some_value> foo;
Upvotes: 5
Reputation: 10614
if you do not want to type namespace sc_dt::
every time, using
the namespace or
using sc_dt::sc_bv;
Upvotes: 3
Reputation: 23711
typedef
s can't be templated. However, using
s can be (and this achieves the desired effect):
template<int W>
using sc_vector = sc_dt::sc_bv<W>;
Upvotes: 5