A
Alex Vinokur
=========================================
Windows 2000
CYGWIN_NT-5.0 1.3.22(0.78/3/2)
GNU gcc version 3.2 20020927 (prerelease)
=========================================
Here is some program which is compiled and works fine.
############################################
====== C++ code : File t1.cpp : BEGIN ======
#include <iostream>
using namespace std;
class BBB
{
public :
void foo1 (int n);
protected :
virtual void foo2(int n) = 0;
};
class DDD : public BBB
{
public :
void foo2(int n);
};
void BBB::foo1 (int n)
{
cout << __PRETTY_FUNCTION__ << " : n = " << n << endl;
foo2(n);
}
void DDD::foo2 (int n)
{
cout << __PRETTY_FUNCTION__ << " : n = " << n << endl;
}
int main ()
{
DDD d;
d.foo1(123);
return 0;
}
====== C++ code : File t1.cpp : END ========
====== Compilation & Run : BEGIN ======
$ g++ t1.cpp
void BBB::foo1(int) : n = 123
virtual void DDD::foo2(int) : n = 123
====== Compilation & Run : END ========
I need something like with template virtual member method.
But template virtual member method is not allowed.
############################################
====== C++ code : File t2.cpp : BEGIN ======
#include <iostream>
using namespace std;
class BBB
{
public :
template <typename T>
void foo1 (const T& t);
protected :
template <typename T>
virtual void foo2(const T& t) = 0; // (Line#12) ILLEGAL because template virtual member method is not allowed
};
class DDD : public BBB
{
public :
template <typename T>
void foo2(const T& t);
};
template <typename T>
void BBB::foo1 (const T& t)
{
cout << __PRETTY_FUNCTION__ << " : t = " << t << endl;
foo2(t);
}
template <typename T>
void DDD::foo2 (const T& t)
{
cout << __PRETTY_FUNCTION__ << " : t = " << t << endl;
}
int main ()
{
DDD d;
d.foo1(123);
return 0;
}
====== C++ code : File t2.cpp : END ========
====== Compilation : BEGIN ======
$ g++ t2.cpp
t2.cpp:12: invalid use of `virtual' in template declaration of `virtual void
BBB::foo2(const T&)'
====== Compilation : END ========
Question.
Is there any bypass to get what I want to ?
Thanks,
==========================================
Alex Vinokur
mailto:[email protected]
http://www.simtel.net/pub/oth/19088.html
http://sourceforge.net/users/alexvn
==========================================
Windows 2000
CYGWIN_NT-5.0 1.3.22(0.78/3/2)
GNU gcc version 3.2 20020927 (prerelease)
=========================================
Here is some program which is compiled and works fine.
############################################
====== C++ code : File t1.cpp : BEGIN ======
#include <iostream>
using namespace std;
class BBB
{
public :
void foo1 (int n);
protected :
virtual void foo2(int n) = 0;
};
class DDD : public BBB
{
public :
void foo2(int n);
};
void BBB::foo1 (int n)
{
cout << __PRETTY_FUNCTION__ << " : n = " << n << endl;
foo2(n);
}
void DDD::foo2 (int n)
{
cout << __PRETTY_FUNCTION__ << " : n = " << n << endl;
}
int main ()
{
DDD d;
d.foo1(123);
return 0;
}
====== C++ code : File t1.cpp : END ========
====== Compilation & Run : BEGIN ======
$ g++ t1.cpp
void BBB::foo1(int) : n = 123
virtual void DDD::foo2(int) : n = 123
====== Compilation & Run : END ========
I need something like with template virtual member method.
But template virtual member method is not allowed.
############################################
====== C++ code : File t2.cpp : BEGIN ======
#include <iostream>
using namespace std;
class BBB
{
public :
template <typename T>
void foo1 (const T& t);
protected :
template <typename T>
virtual void foo2(const T& t) = 0; // (Line#12) ILLEGAL because template virtual member method is not allowed
};
class DDD : public BBB
{
public :
template <typename T>
void foo2(const T& t);
};
template <typename T>
void BBB::foo1 (const T& t)
{
cout << __PRETTY_FUNCTION__ << " : t = " << t << endl;
foo2(t);
}
template <typename T>
void DDD::foo2 (const T& t)
{
cout << __PRETTY_FUNCTION__ << " : t = " << t << endl;
}
int main ()
{
DDD d;
d.foo1(123);
return 0;
}
====== C++ code : File t2.cpp : END ========
====== Compilation : BEGIN ======
$ g++ t2.cpp
t2.cpp:12: invalid use of `virtual' in template declaration of `virtual void
BBB::foo2(const T&)'
====== Compilation : END ========
Question.
Is there any bypass to get what I want to ?
Thanks,
==========================================
Alex Vinokur
mailto:[email protected]
http://www.simtel.net/pub/oth/19088.html
http://sourceforge.net/users/alexvn
==========================================