The problem resides below - I'm trying to make a directive command that disable one constructor definition, or the other, based on the parameter of T. When I uncomment the block around the if statement, I get this error-- ... missing binary operator before token "("
--but when I replace the ( typeid(T).name() == typeid(int).name() ) statement with something like 0 or true the code compiles just fine. Here's the code--
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
template<class T>class Enum;
template<class T>
class Enum
{
public:
struct Case;
/*
#if ( typeid(T).name() == typeid(int).name() )
#define CONSTRUCTOR
Enum(){};
#else
#define CONSTRUCTOR
Enum(){};
#endif*/
private:
Case *cases;
};
template<class T>
struct Enum<T>::Case
{
T value;
string name;
static int total;
Case(T theValue, const char *theName)
: value(theValue), name(theName) {total++;};
};
template<>
struct Enum<int>::Case
{
int value;
string name;
static int total;
Case(const char *theName)
: value(total), name(theName) {total++;};
};
int main(int argc, char *argv[])
{
cout << ( typeid(int).name() == typeid(int).name() ) << endl;
cin.get();
return 0;
}
As you can see, I tested the statement in main and it works perfectly fine, returning a bool value after the comparison. I just don't understand why #if doesn't recognize it as a bool expression.