[prev in list] [next in list] [prev in thread] [next in thread]
List: lyx-devel
Subject: C++ question
From: Angus Leeming <a.leeming () ic ! ac ! uk>
Date: 2002-10-31 10:57:32
[Download RAW message or body]
I read the recent thread about casting Insets up to
their "real" type and thought I'd try and implement André's
asAInset, asBInset, asCInset thing using templates.
Unfortunately, it doesn't compile :-(
Is their anyway to do this?
Angus
class Base {
public:
virtual ~Base() {}
template <typename T>
virtual
T * up_cast() { return 0; }
};
class Derived1 : public Base {
public:
template<>
Derived1 * up_cast() { return this; }
};
class Derived2 : public Base {
public:
template<>
Derived2 * up_cast() { return this; }
};
#include <iostream>
int main ()
{
Base * a = new Derived1;
Base * b = new Derived2;
std::cout << a << ' ' << a->up_cast<Derived2>() << ' '
<< a->up_cast<Derived1>() << std::endl;
return 0;
}
aleem@pneumon:aleem-> cxx -std strict_ansi -o trial trial.C
cxx: Error: trial.C, line 6: "virtual" is not allowed in a function template
declaration
virtual
--------^
cxx: Error: trial.C, line 12: explicit specialization is not allowed in the
current scope
template<>
--------^
cxx: Error: trial.C, line 18: explicit specialization is not allowed in the
current scope
template<>
--------^
cxx: Info: 3 errors detected in the compilation of "trial.C".
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic