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

How to use this member template

Here is a stripped down version of what I am trying to do. I would like
to know how to use this template member function
class B
{
int b;
public:
B() {};
template<class DbTags, class DbNams> int getTgs(int &, DbTags&,
DbNams&);

};
template<class DbTags, class DbNams> int B::getTgs(int& a, DbTags& oTg,
DbNams& oNm)
{
typename DbTags::iterator ip;
typename DbNams::iterator in;
for (ip = oTg.begin(); ip != oTg.end(); ip++)
std::cout << (*ip) << std::endl;
//copy (oTg.begin(), oTg.end(),
std::ostream_iterator<int>(std::cout));
for (in = oNm.begin(); in != oNm.end(); in++)
std::cout << (*in) << std::endl;
}

template<class DbTg> class A
{
int a;
public:
A();

};
template<class DbTg> A::A()
{
B myB;
int f=9;
DbTg oT;
DbNams oN;
oN.push_back("irq_time");
oN.push_back("irq_wait");
oT.push_back(5);
oT.push_back(6);
myB.getTgs(f, oT, oN);
}
int main()
{
A<std::list<int> > myA;

}

My question is how to use B::getTgs in the constructor A. When the
B::getTgs has the first two arguments only I am able to use it. It is
the third argument that is creating the problem

Regards
Ninan

Jul 23 '05 #1
6 1252
"nin234ATIyahoo.com" <ni****@yahoo.com> wrote...
Here is a stripped down version of what I am trying to do. I would like
to know how to use this template member function
class B
{
int b;
public:
B() {};
template<class DbTags, class DbNams> int getTgs(int &, DbTags&,
DbNams&);

};
template<class DbTags, class DbNams> int B::getTgs(int& a, DbTags& oTg,
DbNams& oNm)
{
typename DbTags::iterator ip;
typename DbNams::iterator in;
for (ip = oTg.begin(); ip != oTg.end(); ip++)
std::cout << (*ip) << std::endl;
//copy (oTg.begin(), oTg.end(),
std::ostream_iterator<int>(std::cout));
for (in = oNm.begin(); in != oNm.end(); in++)
std::cout << (*in) << std::endl;
}

template<class DbTg> class A
{
int a;
public:
A();

};
template<class DbTg> A::A()
{
B myB;
int f=9;
DbTg oT;
DbNams oN;
oN.push_back("irq_time");
oN.push_back("irq_wait");
oT.push_back(5);
oT.push_back(6);
myB.getTgs(f, oT, oN);
}
int main()
{
A<std::list<int> > myA;

}

My question is how to use B::getTgs in the constructor A. When the
B::getTgs has the first two arguments only I am able to use it. It is
the third argument that is creating the problem


What problem? I mean, aside from the fact that in the code above,
in the constructor of A, 'DbNams' is undefined, I don't see any
problem. Perhaps you could elaborate on what you're trying to
achieve... Maybe (and this is a pure speculation) you meant to
declare 'oN' a list of something, or maybe (another speculation)
you wanted to add another argument to your 'A' template...

V
Jul 23 '05 #2

Victor Bazarov wrote:
"nin234ATIyahoo.com" <ni****@yahoo.com> wrote...
Here is a stripped down version of what I am trying to do. I would like to know how to use this template member function
class B
{
int b;
public:
B() {};
template<class DbTags, class DbNams> int getTgs(int &, DbTags&, DbNams&);

};
template<class DbTags, class DbNams> int B::getTgs(int& a, DbTags& oTg, DbNams& oNm)
{
typename DbTags::iterator ip;
typename DbNams::iterator in;
for (ip = oTg.begin(); ip != oTg.end(); ip++)
std::cout << (*ip) << std::endl;
//copy (oTg.begin(), oTg.end(),
std::ostream_iterator<int>(std::cout));
for (in = oNm.begin(); in != oNm.end(); in++)
std::cout << (*in) << std::endl;
}

template<class DbTg> class A
{
int a;
public:
A();

};
template<class DbTg> A::A()
{
B myB;
int f=9;
DbTg oT;
DbNams oN;
oN.push_back("irq_time");
oN.push_back("irq_wait");
oT.push_back(5);
oT.push_back(6);
myB.getTgs(f, oT, oN);
}
int main()
{
A<std::list<int> > myA;

}

My question is how to use B::getTgs in the constructor A. When the
B::getTgs has the first two arguments only I am able to use it. It is the third argument that is creating the problem


What problem? I mean, aside from the fact that in the code above,
in the constructor of A, 'DbNams' is undefined, I don't see any
problem. Perhaps you could elaborate on what you're trying to
achieve... Maybe (and this is a pure speculation) you meant to
declare 'oN' a list of something, or maybe (another speculation)
you wanted to add another argument to your 'A' template...

V


Jul 23 '05 #3
Let me clarify this
This works if I change the code like this
template<class DbTg, class DbNams> class A
{
int a;
public:
A();

};
template<class DbTg, class DbNams> A<DbTg, DbNams>::A()
{
B myB;
int f=9;
DbTg oT;
DbNams oN;
oN.push_back("irq_time");
oN.push_back("irq_wait");
oT.push_back(5);
oT.push_back(6);
myB.getTgs(f, oT, oN);
}

int main()
{
A<std::list<int>, std::list<std::string> > myA;

}
But here I am declaring DbNams template for the entire class, whereas
it is just a local variable inside the constructor. Is there a way to
define this template (DbNams) just for the constructor
Victor Bazarov wrote:
"nin234ATIyahoo.com" <ni****@yahoo.com> wrote...
Here is a stripped down version of what I am trying to do. I would like to know how to use this template member function
class B
{
int b;
public:
B() {};
template<class DbTags, class DbNams> int getTgs(int &, DbTags&, DbNams&);

};
template<class DbTags, class DbNams> int B::getTgs(int& a, DbTags& oTg, DbNams& oNm)
{
typename DbTags::iterator ip;
typename DbNams::iterator in;
for (ip = oTg.begin(); ip != oTg.end(); ip++)
std::cout << (*ip) << std::endl;
//copy (oTg.begin(), oTg.end(),
std::ostream_iterator<int>(std::cout));
for (in = oNm.begin(); in != oNm.end(); in++)
std::cout << (*in) << std::endl;
}

template<class DbTg> class A
{
int a;
public:
A();

};
template<class DbTg> A::A()
{
B myB;
int f=9;
DbTg oT;
DbNams oN;
oN.push_back("irq_time");
oN.push_back("irq_wait");
oT.push_back(5);
oT.push_back(6);
myB.getTgs(f, oT, oN);
}
int main()
{
A<std::list<int> > myA;

}

My question is how to use B::getTgs in the constructor A. When the
B::getTgs has the first two arguments only I am able to use it. It is the third argument that is creating the problem


What problem? I mean, aside from the fact that in the code above,
in the constructor of A, 'DbNams' is undefined, I don't see any
problem. Perhaps you could elaborate on what you're trying to
achieve... Maybe (and this is a pure speculation) you meant to
declare 'oN' a list of something, or maybe (another speculation)
you wanted to add another argument to your 'A' template...

V


Jul 23 '05 #4
<ni****@gmail.com> wrote...
[...]
But here I am declaring DbNams template for the entire class, whereas
it is just a local variable inside the constructor. Is there a way to
define this template (DbNams) just for the constructor
Don't call it DbNams. Give it some real type. And don't top-post.
[...]

Jul 23 '05 #5

Victor Bazarov wrote:
<ni****@gmail.com> wrote...
[...]
But here I am declaring DbNams template for the entire class, whereas it is just a local variable inside the constructor. Is there a way to define this template (DbNams) just for the constructor


Don't call it DbNams. Give it some real type. And don't top-post.
[...]


That is obvious. What I wanted was a member template constructor. I
read from older posts in this NG (posted couple of years ago) that it
is not possible. Is it still true

Jul 23 '05 #6
"Ninan Thomas" <ni****@gmail.com> wrote...

Victor Bazarov wrote:
<ni****@gmail.com> wrote...
> [...]
> But here I am declaring DbNams template for the entire class, whereas > it is just a local variable inside the constructor. Is there a way to > define this template (DbNams) just for the constructor


Don't call it DbNams. Give it some real type. And don't top-post.
> [...]


That is obvious. What I wanted was a member template constructor. I
read from older posts in this NG (posted couple of years ago) that it
is not possible. Is it still true


A template constructor in not possible if the template argument is not
among the constructor's arguments. But if it's one of the arguments,
why not?

struct A {
template<class T> A(T blah);
};

int main() {
A a(42); // T is 'int'
}

V
Jul 23 '05 #7

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

Similar topics

0
by: Gianni Mariani | last post by:
I remember seeing a neat template specialization trick posted here a few months ago that allowed the detection of a type containing a member. After a day searching through google archives I come up...
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>
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 {
2
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
5
by: chgans | last post by:
Hi all, I'm having difficulties with some template static member, especially when this member is a template instance, for example: ---- template<typename T> class BaseT { public: static...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.