tempalte as the overloaded conversion operator

class WIDE {
...
template <typename A> operator A () {
A a;
... A::static_member <---- line 20
}
}
template <int x, int y> class NARROW{
static int const static_member;
...
}
WIDE wide;
NARROW<1,2> n12 = (NARROW<1,2>)(wide) <---- line 123

error message:
y.c: In member function ¡®WIDE::operator A() [with A = int]:
y.c:123: instantiated from here
y.c:20: error: 'static_member' is not a member of 'int'

I tried to overload a type conversion operator which converts a type WIDE
to a template-instantiated NARROW. But got above error message. Any
hint? thanks
Why do you have to do this -> template <int x, int y> class NARROW?

Wouldn't it be simpler if x and y where (perhaps static) members of your NARROW class?
But if you really want to go this way, wouldn't it be simpler to do something like

template <int x, int y> operator NARROW<x,y> () {/*...*/}

instead of template <typename A> operator A () {/*...*/}?
Last edited on
Topic archived. No new replies allowed.