Re: Member Templates
From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 05/26/04
- Next message: Daniel T.: "Re: super constructor in C++"
- Previous message: nikola: "Re: exception handling and reference"
- In reply to: Wojtek Michalik: "Member Templates"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 26 May 2004 02:19:37 GMT
"Wojtek Michalik" <wojmichal@poczta.onet.pl> wrote...
> templete <class T>
>
> class MyClass
> {
> private:
> T member1;
> T* member2;
>
> template <class Type2>
> class Embedded
> {
> T foo;
> Type2 something;
> };
> public:
> template <class AnotherType>
> void function(AnotherType arg);
> }
> /* definition of member function template
> template<class T> template <class AnotherType>
> void MyClass< class T>::function(AnotherType arg)
> { /* do something */}
>
> /* instantiation of it */
>
> MyClass<int> example(constructor_args);
> int a;
> example.function( a );
> /*
> I found similiar but longer example in "C++ Primier" of Stanley B. Lippman
> chapter 16.7. The book says nothing about instantiation an use of member
template
> <class Type2> class Embedded.
> Can anybody give me an axample of use of such template ????
> */
I can't think of any use for MyClass::Embedded, but if you need
it instantiated, it should go something like
typename MyClass<int>::Embedded<char> myclass_embedded = { 42, 'F' };
Although, it's impossible to do outside 'MyClass' scope because the
member 'Embedded' is declared "private".
Victor
- Next message: Daniel T.: "Re: super constructor in C++"
- Previous message: nikola: "Re: exception handling and reference"
- In reply to: Wojtek Michalik: "Member Templates"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|