Is this code legal (standard?) c++?

Hi all,

This code compiles just fine on my VS express 2008, and does what it should. Is it legal C++ code? I would be very grateful if someone could test it on another compiler.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "stdafx.h"
#include <iostream>
template <class Object,  int theHashFunction(Object&) >
class HashedListBasicObjectsSpecifyHashFunction
{
public:
  Object x;
  HashedListBasicObjectsSpecifyHashFunction();
};

template <class Object,  int theHashFunction(Object&)>
HashedListBasicObjectsSpecifyHashFunction<Object,theHashFunction >::HashedListBasicObjectsSpecifyHashFunction()
{ Object x;
  theHashFunction(x);
}

int HF1(int& x)
{ std::cout<<100;
  std::cin >>x;
  return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{ HashedListBasicObjectsSpecifyHashFunction<int,HF1> A;
  return 0;
}


My excuses in advance for not reading all the possible documentation on templates, but I think you guys will know right away :)
Thanks and Cheers!
Last edited on
#include "stdafx.h"
No.

_TCHAR
No.

_tmain
No!

EDIT: Oh, and holy crap:
HashedListBasicObjectsSpecifyHashFunction
Last edited on
oops helios,

That is the default C++ project setting on my VS.

I was asking for the template classes.

Is this:
1
2
3
4
5
6
7
8
9
10
11
12
13
template <class Object,  int theHashFunction(Object&) >
class HashedListBasicObjectsSpecifyHashFunction
{
public:
  Object x;
  HashedListBasicObjectsSpecifyHashFunction();
};

template <class Object,  int theHashFunction(Object&)>
HashedListBasicObjectsSpecifyHashFunction<Object,theHashFunction >::HashedListBasicObjectsSpecifyHashFunction()
{ Object x;
  theHashFunction(x);
}

fine?
It looks fine, but for God's sake, trim those identifiers. It feels like I'm being stabbed in the eye. With words!

EDIT: Wait, what's the point of HashedListBasicObjectsSpecifyHashFunction::x?
Last edited on
Just modified it to look more reasonably. Still my question remains, is this standard?
1
2
3
4
5
6
7
8
9
10
11
12
template <class Object,  int Function(Object&) >
class A
{
public:
  Object x;
  A();
};

template <class Object,  int Function(Object&)>
A<Object,Function>::A()
{  Function(this->x);
}


[Edit:] Sorry, I didn't clip my original example to the possible minimum. HashedListBasicObjectsSpecifyHashFunction::x was an unwanted artefact from my experimentation.
Last edited on
I said it looked fine, what else do you want? GCC doesn't complain.
Topic archived. No new replies allowed.