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

Default for template parameter - how to make it work?

Yan
I have the following code that the compiler complains about that "No
parameters provided for template". The compiler is the one that comes
with Sun Solaris, not sure what exactly. I have no control over what
compiler is to be used, so I just want to know whether the code is
wrong (in which case could you please show me the correct version) or
the compiler isn't up-to-date.

Here is the code:
---------------------------------
template <typename T = intclass C {};

int main() {
C c; // that is the line that the compiler is complaining about
return 0;
}
--------------------------------

Thanks a lot!

Mar 27 '07 #1
5 1978
Yan
On Mar 27, 4:20 pm, "Yan" <yvinogra...@gmail.comwrote:
I have the following code that the compiler complains about that "No
parameters provided for template". The compiler is the one that comes
with Sun Solaris, not sure what exactly. I have no control over what
compiler is to be used, so I just want to know whether the code is
wrong (in which case could you please show me the correct version) or
the compiler isn't up-to-date.

Here is the code:
---------------------------------
template <typename T = intclass C {};

int main() {
C c; // that is the line that the compiler is complaining about
return 0;}

--------------------------------

Thanks a lot!
Changing the line in question to "C<intc" makes the compilation
error go away, but defeats the purpose. Anyways, if someone could
please tell me whether there is a problem with the code I posted or
with the compiler I am using I'd greatly appreciate that.

Mar 27 '07 #2
Yan wrote:
On Mar 27, 4:20 pm, "Yan" <yvinogra...@gmail.comwrote:
>I have the following code that the compiler complains about that "No
parameters provided for template". The compiler is the one that comes
with Sun Solaris, not sure what exactly. I have no control over what
compiler is to be used, so I just want to know whether the code is
wrong (in which case could you please show me the correct version) or
the compiler isn't up-to-date.

Here is the code:
---------------------------------
template <typename T = intclass C {};

int main() {
C c; // that is the line that the compiler is complaining about
return 0;}

--------------------------------

Thanks a lot!

Changing the line in question to "C<intc" makes the compilation
error go away, but defeats the purpose. Anyways, if someone could
please tell me whether there is a problem with the code I posted or
with the compiler I am using I'd greatly appreciate that.
Try

C<c;

The point here is that 'C' is a "template-id" and it has to be followed
by the angle bracket _outside_ the template itself.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Mar 27 '07 #3
Yan
On Mar 27, 4:57 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Yan wrote:
On Mar 27, 4:20 pm, "Yan" <yvinogra...@gmail.comwrote:
I have the following code that the compiler complains about that "No
parameters provided for template". The compiler is the one that comes
with Sun Solaris, not sure what exactly. I have no control over what
compiler is to be used, so I just want to know whether the code is
wrong (in which case could you please show me the correct version) or
the compiler isn't up-to-date.
Here is the code:
---------------------------------
template <typename T = intclass C {};
int main() {
C c; // that is the line that the compiler is complaining about
return 0;}
--------------------------------
Thanks a lot!
Changing the line in question to "C<intc" makes the compilation
error go away, but defeats the purpose. Anyways, if someone could
please tell me whether there is a problem with the code I posted or
with the compiler I am using I'd greatly appreciate that.

Try

C<c;

The point here is that 'C' is a "template-id" and it has to be followed
by the angle bracket _outside_ the template itself.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Thanks Victor,

Unfortunately it also defeats the purpose in a way. There is this
class that is used all over the place and I want to turn it into a
templated one. But I don't want to make numerous changes wherever it's
used in the code and insert the template parameters. I would much
rather use the default parameters to avoid changes in the 'legacy'
code, but it looks like that is not an option.

Yan

Mar 27 '07 #4
Yan wrote:
On Mar 27, 4:57 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>Yan wrote:
>>On Mar 27, 4:20 pm, "Yan" <yvinogra...@gmail.comwrote:
I have the following code that the compiler complains about that
"No parameters provided for template". The compiler is the one
that comes with Sun Solaris, not sure what exactly. I have no
control over what compiler is to be used, so I just want to know
whether the code is wrong (in which case could you please show me
the correct version) or the compiler isn't up-to-date.
>>>Here is the code:
---------------------------------
template <typename T = intclass C {};
>>>int main() {
C c; // that is the line that the compiler is complaining about
return 0;}
>>>--------------------------------
>>>Thanks a lot!
>>Changing the line in question to "C<intc" makes the compilation
error go away, but defeats the purpose. Anyways, if someone could
please tell me whether there is a problem with the code I posted or
with the compiler I am using I'd greatly appreciate that.

Try

C<c;

The point here is that 'C' is a "template-id" and it has to be
followed by the angle bracket _outside_ the template itself.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

Thanks Victor,

Unfortunately it also defeats the purpose in a way. There is this
class that is used all over the place and I want to turn it into a
templated one. But I don't want to make numerous changes wherever it's
used in the code and insert the template parameters. I would much
rather use the default parameters to avoid changes in the 'legacy'
code, but it looks like that is not an option.
Then your only option is

template<class Tclass C_t { ..
typedef C_t<intC;

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Mar 27 '07 #5
Yan
On Mar 27, 5:46 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Yan wrote:
On Mar 27, 4:57 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Yan wrote:
On Mar 27, 4:20 pm, "Yan" <yvinogra...@gmail.comwrote:
I have the following code that the compiler complains about that
"No parameters provided for template". The compiler is the one
that comes with Sun Solaris, not sure what exactly. I have no
control over what compiler is to be used, so I just want to know
whether the code is wrong (in which case could you please show me
the correct version) or the compiler isn't up-to-date.
>>Here is the code:
---------------------------------
template <typename T = intclass C {};
>>int main() {
C c; // that is the line that the compiler is complaining about
return 0;}
>>--------------------------------
>>Thanks a lot!
>Changing the line in question to "C<intc" makes the compilation
error go away, but defeats the purpose. Anyways, if someone could
please tell me whether there is a problem with the code I posted or
with the compiler I am using I'd greatly appreciate that.
Try
C<c;
The point here is that 'C' is a "template-id" and it has to be
followed by the angle bracket _outside_ the template itself.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Thanks Victor,
Unfortunately it also defeats the purpose in a way. There is this
class that is used all over the place and I want to turn it into a
templated one. But I don't want to make numerous changes wherever it's
used in the code and insert the template parameters. I would much
rather use the default parameters to avoid changes in the 'legacy'
code, but it looks like that is not an option.

Then your only option is

template<class Tclass C_t { ..
typedef C_t<intC;

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
neat! thanks Victor!

Mar 27 '07 #6

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

Similar topics

2
by: Michael Stembera | last post by:
I would like to use default parameters in nested templates but MS VC++ 7.1 chokes on it. Does anyone know how to fix the simple example below or if indeed it is possible? template <int N=7>...
3
by: CoolPint | last post by:
Can anyone explain how I can make the following function accept an default arguement for the last parameter, which should be an optional functor? template <typename T, typename FUNCTOR> void...
11
by: BRG | last post by:
I know that default template arguments cannot be used in function templates but are default function parameters legal? That is, is this: ---------------------------------- #include <functional>...
3
by: Capstar | last post by:
Hi NG, I am trying to get the attached piece of code to work, but I can't figure out what I'm doing wrong. To me it seems that when I don't pass an argument to x::do_something, it should use the...
2
by: xuatla | last post by:
The following is just a sample code to demostrate my question: ----------- template <typename T> class C { public: friend void f1(double i=2) { std::cout << i; } ; };
5
by: asianmuscle | last post by:
I am trying to learn RAII and some template techniques by writer a smarter pointer class to manage the resource management. Since I find that a lot of the resource management is kinda the same, I...
12
by: aaragon | last post by:
Hello all. I have a simple question that seems trivial but I can't make it to work. I have a class that takes as a template argument, another class. The idea is as follows: #include...
6
by: Tim Frink | last post by:
Hi, how can I set default values to template parameters? I've this code: class A { template<typename T> void foo( string = "", T* = 0, bool (T::*func)(void) = 0 );
8
by: William Xu | last post by:
Compiling: template <class T = int> T foo(const T& t) {} int main(int argc, char *argv) {} gcc complains:
2
by: Clyde | last post by:
Hi, what i'm trying to do is: /////////////// Code Start template <class TType, int* p = 0> class Template { 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: 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: 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: 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
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
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...

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.