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

templated return

P: n/a
hi all,
I have the following situation:

template <typename _Ta>
class A
{
template <size_t _Tsize>
struct B
{
char buffer[_Tsize];
};
};
The thing is, I need to define a function which returns struct B, but not
with a pre-defined template-argument _Tsize. I have been trying some things
like:

template <typename _Ta>
class A
{
...
template <typename _Tsize>
B<_Tsize> GetB()
{
return B<_Tsize>();
}
};
and attempted to call this function as follows:

A<int> a;
A<int>::B<1> b = a.GetB<1>();
But this doesn't seem to make it through my Visual C++ 6.0 compiler (wierd
stuff with operators for the std::vector are popping up). Can anybody tell
me if there even is a standard c++ way for doing this ?

thanks ahead,
richard
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
RA Scheltema wrote:
hi all,
I have the following situation:

template <typename _Ta>
class A
{
template <size_t _Tsize>
struct B
{
char buffer[_Tsize];
};
};
The thing is, I need to define a function which returns struct B, but not
with a pre-defined template-argument _Tsize. I have been trying some things
like:

template <typename _Ta>
class A
{
...
template <typename _Tsize>
B<_Tsize> GetB()
{
return B<_Tsize>();
}
};
and attempted to call this function as follows:

A<int> a;
A<int>::B<1> b = a.GetB<1>();
But this doesn't seem to make it through my Visual C++ 6.0 compiler (wierd
stuff with operators for the std::vector are popping up). Can anybody tell
me if there even is a standard c++ way for doing this ?

thanks ahead,
richard


Rename your template parameters. Leading underscore followed by a cap is reserved.

Jul 22 '05 #2

P: n/a
"RA Scheltema" <r.a.scheltema[viral][s][p]@[m]dacolian.nl> wrote...
I have the following situation:

template <typename _Ta>
If this is your code, you shouldn't be using such names. Any name
that starts with an underscore and a capital letter is _reserved_.
Why in the world do you need the leading underscore?
class A
{
template <size_t _Tsize>
Same here.
struct B
{
char buffer[_Tsize];
};
};
The thing is, I need to define a function which returns struct B, but not
with a pre-defined template-argument _Tsize. I have been trying some things like:

template <typename _Ta>
class A
{
...
template <typename _Tsize>
B<_Tsize> GetB()
{
return B<_Tsize>();
}
};
and attempted to call this function as follows:

A<int> a;
A<int>::B<1> b = a.GetB<1>();
But this doesn't seem to make it through my Visual C++ 6.0 compiler (wierd
stuff with operators for the std::vector are popping up). Can anybody tell
me if there even is a standard c++ way for doing this ?


Try a different compiler. VC++ 6 is really bad wrt templates.

Victor
Jul 22 '05 #3

P: n/a
RA Scheltema wrote:
...
I have the following situation:

template <typename _Ta>
class A
{
template <size_t _Tsize>
struct B
{
char buffer[_Tsize];
};
};
The thing is, I need to define a function which returns struct B, but not
with a pre-defined template-argument _Tsize. I have been trying some things like:

template <typename _Ta>
class A
{
...
template <typename _Tsize>
B<_Tsize> GetB()
{
return B<_Tsize>();
}
};
...
This doesn't make much sense. Template 'B' is declared as accepting a
non-type parameter (a value of type 'size_t') and you are trying to
specialize it with type argument.
and attempted to call this function as follows:

A<int> a;
A<int>::B<1> b = a.GetB<1>();


Here again, you are trying to specialize 'GetB' with non-type argument,
while template 'GetB' expects a type argument.

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.