Re: Need template work-around in VC6



Carl Daniel [VC++ MVP] wrote:
"mlimber" <mlimber@xxxxxxxxx> wrote in message
news:1156357989.032727.206660@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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

.



Relevant Pages

  • Re: Need template work-around in VC6
    ... struct Int2Type ... void Baz(const Int2Type&) ... ugly work-around with Int2Type that is shown, ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Function pointer to void function and int function
    ... struct foo f; ... ... If you call such a function through a `)' pointer, the compiler will not know it's supposed to generate the hidden `_value_ptr' argument nor the hidden `_returned_struct' object it should point to. ... that calls a function returning `int' and ignores the returned ... value is identical to the machinery that calls a `void' function. ...
    (comp.lang.c)
  • Re: alignment/zero length arrays
    ... The lists contain a void *, ... struct foo *f; ... This sets pointer f to point to the data in your element. ...
    (comp.lang.c)
  • Re: struct data offsets
    ... void say_hi; ... Function pointers are a very, very good reason to use typedefs. ...
    (comp.lang.c)
  • Re: Opaque pointers
    ... pete wrote: ... extern T List_list (void *x, ... In your header file, you'd have something along the lines of: ... The actual definition of 'struct foo' goes in the source file: ...
    (comp.lang.c)