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

Need template work-around in VC6

I am using VC++ 6 (sp6) and cannot change compilers. I have something
akin to this code:

#include <iostream>
using namespace std;

template<int i>
struct Int2Type
{
enum { value = i };
};

struct Foo
{
template<int i>
void Bar()
{
cout << i << endl;
}

// Ugly work-around
template<int i>
void Baz( const Int2Type<i>& )
{
cout << i << endl;
}
};

int main()
{
Foo f;
f.Bar<42>(); // Error here
f.Baz( Int2Type<42>() );
return 0;
}

The error message is: "error C2059: syntax error : ')'". I can use the
ugly work-around with Int2Type that is shown, but I would much prefer
something simpler and more aesthetically pleasing. Any ideas?

Cheers! --M

Aug 23 '06 #1
6 1212

"mlimber" <ml*****@gmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
>I am using VC++ 6 (sp6) and cannot change compilers. I have something
akin to this code:

#include <iostream>
using namespace std;

template<int i>
struct Int2Type
{
enum { value = i };
};

struct Foo
{
template<int i>
void Bar()
{
cout << i << endl;
}

// Ugly work-around
template<int i>
void Baz( const Int2Type<i>& )
{
cout << i << endl;
}
};

int main()
{
Foo f;
f.Bar<42>(); // Error here
f.Baz( Int2Type<42>() );
return 0;
}

The error message is: "error C2059: syntax error : ')'". I can use the
ugly work-around with Int2Type that is shown, but I would much prefer
something simpler and more aesthetically pleasing. Any ideas?
For VC6? No, not really (not that I've seen anyway). The parser simply
doesn't understand explicit template arguments on a function invocation.

-cd
Aug 23 '06 #2
Carl Daniel [VC++ MVP] wrote:
"mlimber" <ml*****@gmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
I am using VC++ 6 (sp6) and cannot change compilers. I have something
akin to this code:

#include <iostream>
using namespace std;

template<int i>
struct Int2Type
{
enum { value = i };
};

struct Foo
{
template<int i>
void Bar()
{
cout << i << endl;
}

// Ugly work-around
template<int i>
void Baz( const Int2Type<i>& )
{
cout << i << endl;
}
};

int main()
{
Foo f;
f.Bar<42>(); // Error here
f.Baz( Int2Type<42>() );
return 0;
}

The error message is: "error C2059: syntax error : ')'". I can use the
ugly work-around with Int2Type that is shown, but I would much prefer
something simpler and more aesthetically pleasing. Any ideas?

For VC6? No, not really (not that I've seen anyway). The parser simply
doesn't understand explicit template arguments on a function invocation.
Except for free-standing functions, of course. Thanks for responding!

Cheers! --M

Aug 24 '06 #3
mlimber wrote:
Carl Daniel [VC++ MVP] wrote:
>For VC6? No, not really (not that I've seen anyway). The parser simply
doesn't understand explicit template arguments on a function invocation.

Except for free-standing functions, of course. Thanks for responding!
Right - the member function template support is extremely patchy. And
for free standing functions, you have to make sure that T is present
somewhere in the function signature in any case (e.g.
template <class T>
void f(T* t = 0); //default parameter to make sure VC6 doesn't
//collapse all instantiations into one.
//f<int>() should work though, IIRC.

Any reason why you're using an 8 year old compiler? That would be like
still using egcs rather than GCC!

Tom
Aug 25 '06 #4
Tom Widmer [VC++ MVP] wrote:
Any reason why you're using an 8 year old compiler? That would be like
still using egcs rather than GCC!
Because I'm working with legacy code, and the management wants to avoid
surprises. Me, I like surprises. :-)

Cheers! --M

Aug 25 '06 #5

"mlimber" <ml*****@gmail.comskrev i meddelandet
news:11*********************@p79g2000cwp.googlegro ups.com...
Tom Widmer [VC++ MVP] wrote:
>Any reason why you're using an 8 year old compiler? That would be
like
still using egcs rather than GCC!

Because I'm working with legacy code, and the management wants to
avoid
surprises. Me, I like surprises. :-)

Cheers! --M
And the fact that it doesn't work is no surprise. Then what? :-)
Bo Persson
Aug 25 '06 #6

"Tom Widmer [VC++ MVP]" <to********@hotmail.comskrev i meddelandet
news:%2****************@TK2MSFTNGP06.phx.gbl...
mlimber wrote:
>Carl Daniel [VC++ MVP] wrote:
>>For VC6? No, not really (not that I've seen anyway). The parser
simply
doesn't understand explicit template arguments on a function
invocation.

Except for free-standing functions, of course. Thanks for
responding!
It just looks that way, until you try to use several different
instantiations!
>
Right - the member function template support is extremely patchy.
And for free standing functions, you have to make sure that T is
present somewhere in the function signature in any case (e.g.
template <class T>
void f(T* t = 0); //default parameter to make sure VC6 doesn't
//collapse all instantiations into one.
//f<int>() should work though, IIRC.
The compiler actually works (almost :-) correctly for the free
functions, in that it produces one set of code for each instantiation.
Unfortunately they all have the same signature,
void-f-with-no-parameters.

Then, of course, the linker can't tell them apart so we don't know
which one we get.
>
Any reason why you're using an 8 year old compiler? That would be
like still using egcs rather than GCC!
Right.

"To avoid surprises". :-)
Bo Persson
Aug 25 '06 #7

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

Similar topics

5
by: Bernard | last post by:
Hi, I have a problem with a CGI script (Perl) on a Win2000 server. The script is for sending E-cards and was written by Jason Maloney:...
3
by: Mr. Clean | last post by:
Very new to XML style sheets and need some help getting this XML: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE CDSLogger SYSTEM "CDSLogger.dtd"> <CDSLogger> <ErrorObject> <BatchName>This...
1
by: David2511 | last post by:
Hello, I need a little help. I try to write the following architecture : an abstract template class A Two classes derived from class A : the classes B and C which are concrete. The class...
7
by: Christian Christmann | last post by:
Hi, in the past I always appreciated your help and hope that you also can help me this time. I've spent many many hours but still can't solve the problem by myself and you are my last hope. ...
11
by: Micha | last post by:
Hello there, I think I've run into some classic c++ pitfall and maybe some of you guys can help me out. For my project I will need to use matrices and vectors and so I decided to implement them...
4
by: Piper707 | last post by:
I need help with using a general template which would process all tags other than the ones for which specific templates have been written. My XML looks like this: <ITEMS>...
3
by: vijaykokate | last post by:
Our company http://www.softnmation.com/ offers its customers a great variety of products. Everything you need can be found in this site. Web Template, CSS Template, Logo Template, Corporate...
5
by: Grizlyk | last post by:
I found, that I must write explicit cast from non-const reference to const reference. I have a class with member returning non-const reference to itself template<class A,class B,class C>...
15
by: Jess | last post by:
Hello, Sometimes declarations are all what we need when we define/declare classes (or functions?), but sometimes we need definitions. I learned that if we define a class (B) that has an object...
5
by: iapx86 | last post by:
My parser project calls for a computed goto (see code below). The C preprocessor delivers the desired result, but is ugly. Template metaprogramming delivers results I do not understand. Can...
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...
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
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
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,...
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.