Re: EVC++: compile errors disappear when preprocessor output is on

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Just figured I'd give a little update. So, the fact that the
preprocessor output made the errors disappear is due to my own
sillyness for confusing /P and /E. The problem still remained that the
compiler gives a lot of syntax errors when I used my new template class
as a member variable of an existing class, while it worked fine in the
unit test. So, temporarily, I removed the template class, and replaced
it with a new, much simpler class to at least make progress. At some
point, I decided I needed a templated constructor for that one though,
so I could initialize the member using different enum types, in this
case (don't ask). So I introduced something along the lines of:

class MyClass
{
public:
MyClass(const int i): m_i(i) {}

template <typename T>
MyClass(const T t): m_i(static_cast<int>(t)) {}

private:
int m_i;
};

and presto! I got heaploads of syntax errors again. Just on a hunch, I
changed the line
MyClass(const T t)
to
MyClass(const T& t)
and it worked again, no more compile errors! I have no idea why one
works and the other doesn't, but that's how it seems to be.

Turned out that the previous, more elaborate template class also had a
constructor of this form. Changing its argument to a reference to T
also solved that one's compile errors when I used it as a member
variable. So I now know what is causing those mysterious compile
errors, I just still don't know why. I guess it's just this compiler's
bad support for templates, or something. Anyone know why
const-reference-to-T works and const-T-by-value doesn't? Is this a
known rule of thumb to get EVC++/VC6 to use templated constructors
properly?

.



Relevant Pages

  • Possible g++ bug in template parsing
    ... The attached code compiles and works properly when I comment out the ... declaration, definition, and invocations of the method 'eck'. ... Note that 'gak' (a template function in a template class) works, ...
    (comp.lang.cpp)
  • Re: Curing Lycanthropy
    ... There's a reason I recommend the lycanthrope template classes from the Wizards ... take the next X levels in the template class and the animal class. ... Who do you blame when your kid is a - brat? ...
    (rec.games.frp.dnd)
  • Re: what about the template error??
    ... > template<class T,int MAXMIZE> ... at that point that the compiler knows the template parameters. ... that it knows all the details of the template class that are required. ...
    (microsoft.public.vc.stl)
  • Re: Keeping the template implementation in .C
    ... > It is necessary to compile the whole template code with the type of the ... > correct object code and can not check if the template parameter meets all ... class-independent part of your template class into another class. ...
    (comp.unix.programmer)
  • Template class and __nogc
    ... Can I define a template class as following ... I got hundreds compile errors, ... '__nogc' cannot be applied to a template ... Prev by Date: ...
    (microsoft.public.dotnet.languages.vc)