473,385 Members | 1,753 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,385 software developers and data experts.

template instance in normal class

Hi,

Can anybody give an example of template class instance in a normal
class.
I tried three books and around 5 top sites to get an answer.

Jun 11 '06 #1
4 1851
sahpathi wrote:
Hi,

Can anybody give an example of template class instance in a normal
class.
I tried three books and around 5 top sites to get an answer.


template <typename T>
class A{};

class B
{
public:
A<int> a;
std::vector<float> v;
std::pair<int, double> pr;

// etc...
};

Regards,
Ben
Jun 11 '06 #2

sahpathi wrote:
Hi,

Can anybody give an example of template class instance in a normal
class.
I tried three books and around 5 top sites to get an answer.


// template class examples
//
// generic template class
template<class Item>
class myobject
{
public:
myobject();
private:
Item data;
};
//class imlementation
template<class Item>
myobject::myobject()
{
.....
}

int main()
{
//calling temlate class

myobject<int> testobject;
myobject<char> testobject;
return 0;
}

Regards,
Lucman <fe****@gmail.com>

Jun 11 '06 #3
Lucman wrote:
sahpathi wrote:
Hi,

Can anybody give an example of template class instance in a normal
class.
I tried three books and around 5 top sites to get an answer.


// template class examples
//
// generic template class
template<class Item>
class myobject
{
public:
myobject();
private:
Item data;
};
//class imlementation
template<class Item>
myobject::myobject()
{
.....
}

int main()
{
//calling temlate class

myobject<int> testobject;
myobject<char> testobject;
return 0;
}

Regards,
Lucman <fe****@gmail.com>

There is no issue for instantiation in main. But when I instance it in
ANOTHER CLASS, that is when it creates problems.

Jun 12 '06 #4

sahpathi wrote:
Lucman wrote:
sahpathi wrote:
Hi,

Can anybody give an example of template class instance in a normal
class.
I tried three books and around 5 top sites to get an answer.


// template class examples
//
// generic template class
template<class Item>
class myobject
{
public:
myobject();
private:
Item data;
};
//class imlementation
template<class Item>
myobject::myobject()
{
.....
}

int main()
{
//calling temlate class

myobject<int> testobject;
myobject<char> testobject;
return 0;
}

Regards,
Lucman <fe****@gmail.com>

There is no issue for instantiation in main. But when I instance it in
ANOTHER CLASS, that is when it creates problems.


Hey thanks. It is done now.

Jun 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gert Van den Eynde | last post by:
Hi all, A beginners question.... I've got a template class template <class T> classA {...} In an other class, I want to pass a pointer to an instance of classA as a function argument....
5
by: Pelle Beckman | last post by:
Hi, I've done some progress in writing a rather simple singleton template. However, I need a smart way to pass constructor arguments via the template. I've been suggested reading "Modern C++...
6
by: RainBow | last post by:
Greetings!! I introduced the so-called "thin-template" pattern for controlling the code bloat caused due to template usage. However, one of the functions in the template happens to be virtual...
4
by: Brian Barnes | last post by:
I am trying to create a template code behind file for a website which all pages should be inherited from. This base class however, when I try to view the aspx page in Visual studio .NET (2002), it...
0
by: magicofureyes | last post by:
Hello Guys im a just a new user and i dnt knw much abt Xml i want to upload a new template in Blogger so got some free coding but when i save this code in Blogger template it say '''' Your...
1
by: newbie | last post by:
Here is my question: I want to have a class, which requires a typename T with interface "operate()" and "Init()" as its parameter. template <class Tclass Foo { public: Foo(int param) {...
8
by: flopbucket | last post by:
Hi, I want to provide a specialization of a class for any type T that is a std::map. template<typename T> class Foo { // ... };
32
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template...
5
by: (2b|!2b)==? | last post by:
I would like to know if I can specialize only a specific method for a class template. Is the (specialization) code below valid? template <typename T1, typename T2> class MyClass { public:
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.