Here's a puzzle: I'd like to define something like
typedef std::pair
On Sunday 21 August 2005 3:51 pm, John D Lamb wrote:
Here's a puzzle: I'd like to define something like
typedef std::pair
P; I can obviously do
class P : public std::pair
{}; or
typedef std::pair
P; In this case, you have not yet defined P. You could use a forward declaration, such as: class P; Then, typedef std::pair P; should work. I have not tried your example specifically. -- Jerry Feldman Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
Jerry Feldman wrote:
On Sunday 21 August 2005 3:51 pm, John D Lamb wrote:
Here's a puzzle: I'd like to define something like
typedef std::pair
P; I can obviously do
class P : public std::pair
{}; or
typedef std::pair
P; In this case, you have not yet defined P. You could use a forward declaration, such as: class P; Then, typedef std::pair P; should work. I have not tried your example specifically.
Sadly it doesn't work though I actually had to try this to see. It does
confirm that I'm not being totally stupid in thinking that C++ might
reasonably allow this sort of thing.
The C++ standard doesn't allow you to use typedef for a name already
declared in the same scope.
I think C++ won't allow you to do something like:
class X
Hello Jerry,
I tried this and It worked for me on g++ (3.4.4).
#include<list>
using namespace std;
std::list
Jerry Feldman wrote:
On Sunday 21 August 2005 3:51 pm, John D Lamb wrote:
Here's a puzzle: I'd like to define something like
typedef std::pair
P; I can obviously do
class P : public std::pair
{}; or
typedef std::pair
P; In this case, you have not yet defined P. You could use a forward declaration, such as: class P; Then, typedef std::pair P; should work. I have not tried your example specifically. Sadly it doesn't work though I actually had to try this to see. It does confirm that I'm not being totally stupid in thinking that C++ might reasonably allow this sort of thing.
The C++ standard doesn't allow you to use typedef for a name already declared in the same scope.
I think C++ won't allow you to do something like:
class X
x; i.e. create a template class whose template parameter is a pointer to an object of this class. It will allow
class Y : public class X
{} x; which is nearly the same.
For my own problem, I've worked out I can use static_cast rather than reinterpret_cast, which is a bit of an improvement.
-- JDL
-- To unsubscribe, email: suse-programming-e-unsubscribe@suse.com For additional commands, email: suse-programming-e-help@suse.com Archives can be found at: http://lists.suse.com/archive/suse-programming-e
vamsi krishna wrote:
I tried this and It worked for me on g++ (3.4.4).
#include<list> using namespace std;
std::list
P; /*I tried for list template, it should work for pair also*/ typedef class P* Y; typdef std::list<Y> P_new; /*P_new is the class what u are expecting.*/
Unfortunately it doesn't quite work though it took me a while to work
out why: I hadn't thought of declaring a class inside the brackets <...>.
There are two classes P here I think: one declared but not defined and
the other defined as std::list
participants (3)
-
Jerry Feldman
-
John D Lamb
-
vamsi krishna