473,396 Members | 1,605 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Member Templates

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
1 1528
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brian Ross | last post by:
Hi, I am having a problem writing a constructor/member initialization with VC.NET7.1. Here is the code: --- namespace Library
2
by: Simon G Best | last post by:
Hello! I have a query regarding explicit specialisation of class templates which are themselves members of class templates. Here's what I want to do: template< class T > struct pink { ...
3
by: Dave | last post by:
Hello all, I am trying to create a full specialization of a member function template of a class template. I get the following errors: Line 29: 'foo<T1>::bar' : illegal use of explicit...
5
by: Levent | last post by:
Hi, Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1): #include <iostream> template<class T, unsigned N> struct Foo { void func(); }; template<class T, unsigned N>
9
by: Ian | last post by:
Can it be done? If so, what's the syntax. For example a full specialisation, template <typename T> struct X { template <typename C> void foo( C a ) {} };
4
by: Joseph Turian | last post by:
Hi, What is the correct syntax to get the bar<T>::f<int, unsigned>() function to compile in the following fragment? Thanks, Joseph class foo {
8
by: Rahul | last post by:
Hi, Is there a way to partially specialize only a member function of a template class (not the whole class). e.g. template <typename A, typename B> class Base { public:
13
by: mike b | last post by:
Hello everyone, thanks in advance for your help. I'm new to C++ templates and have run into some issues using member function templates. I have a shared library containing templates that I'm...
15
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
10
by: Jeffrey | last post by:
My understanding is that if you write class X { int y; static int z; }; then you've defined (and declared) X and y, but you have only declared (and not defined) z. If you'd like to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.