Re: How to make obj of temp in temp ???
- From: "Frank Hickman [MVP]" <fhickman_NOSP@xxxxxxxxxxxxxxx>
- Date: Tue, 12 Apr 2005 01:28:04 -0400
"IceColdFire" <IceColdFire@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:799EED05-7526-4158-9BF9-75BB2EB4B4F5@xxxxxxxxxxxxxxxx
> Hi,
> How do I make objects of class D :::
> ---
> template<class T>
> class C
> {
> public:
> T i;
> C(T arg):i(arg){ }
> template<class U>
> class D
> {
> U j;
> D(U arg):i(arg){ }
> };
> };
> ----
> in main()
> ???
> Urgent !!!
> a.a.cpp
First of all, in it's present form you cannot. The class you have defined
within your C class, D, has no public constructor and therefore cannot be
instantiated. Then you need to fix the typo in the variable initialization
in D's constructor. Then you could declare a variable of class D by doing
this, although I see no good reason or benefit for implementing anything
like this...
template< class T >
class C
{
public:
T i;
C( T arg ) : i( arg ) { }
template< class U >
class D
{
public:
U j;
D( U arg ) : j( arg ) { }
};
};
C<int>::D<double> d( 5.2 );
You are effectively taking up memory that you cannot access and/or use,
class C's integer (in this case) cannot be accessed from d. Nor could any
member functions if they existed, unless of course if they are static
members.
But maybe I just cannot see a good reason, does anyone else see a benefit to
this?
--
============
Frank Hickman
Microsoft MVP
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.
.
- Follow-Ups:
- Re: How to make obj of temp in temp ???
- From: IceColdFire
- Re: How to make obj of temp in temp ???
- References:
- How to make obj of temp in temp ???
- From: IceColdFire
- How to make obj of temp in temp ???
- Prev by Date: Re: external class
- Next by Date: Re: How to make obj of temp in temp ???
- Previous by thread: How to make obj of temp in temp ???
- Next by thread: Re: How to make obj of temp in temp ???
- Index(es):
Relevant Pages
|