By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 827 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

Member Templates

P: n/a
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 ????
*/

Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Wojtek Michalik" <wo*******@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
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.