Re: Member Templates

From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 05/26/04


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



Relevant Pages

  • Re: template codegeneration issues
    ... The template classes contain ... It can be easily observed in the debbuger and it looks like certain member variables and const members are placed at the same ...
    (microsoft.public.dotnet.languages.vc)
  • Re: static variable
    ... >> class MyClass ... >> private: ... >> can I initialize this bool var? ... Little Problem,Guy declared Static Member Public, so you can't initialise ...
    (microsoft.public.vc.mfc)
  • Re: How do I write to a textbox in a form from within a class
    ... you can control the level of access for each class member. ... Protected Friend ... Private PrivateVar As Integer ... to your TextBox issue ... ...
    (microsoft.public.dotnet.languages.vb)
  • Re: "this" and "base"
    ... compiler and the programming language. ... a private inherited field in a base class from a derived class is that the ... > because the member "is a private". ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: "this" and "base"
    ... "What keeps you from accessing a Private member" is more of what you are ... It is both the Compiler and Runtime engine that keep you from ... member function in your derived class you could have a local variable called ...
    (microsoft.public.dotnet.languages.csharp)