Topic: template instantiation/parsing question
Author: lipp@zhora.symbologic.com (Damon Lipparelli)
Date: 1996/02/22 Raw View
I'm in the process of porting some older C++ code to several newer
compilers. The newer compilers (Visual C++ 4.0, G++ 2.7.2, and others) are
having problems with template constructs that have compiled for years under
our current compiler (Sun's SPARCworks 4.0.1). I've been fighting my way
through the DWP, but I haven't been able to tell if the problematic code
_should_ work or not.
In short, I think the problem comes from wrapping a declared template type
around a forward referenced class type. I've included a code snippet that
I think demonstrates the problem.
--- Cut Here ---
class base
{
public:
};
class tmpl_base
{
public:
tmpl_base(void);
tmpl_base(base& b);
private:
base& b_;
};
template<class T>
class tmpl : public tmpl_base
{
public:
tmpl(void)
{}
tmpl(T& t)
: tmpl_base(t)
{}
};
class foo;
class bar
{
public:
bar(void);
private:
tmpl<foo> foo_;
};
--- Cut Here ---
The Sun compiler accepts this without a complaint. All of the other
compilers that I've tried compiling this under complain about the
"tmpl<foo> foo_;" in the declaration of "class bar". If I replace this
line with "tmpl<foo>& foo_;", it compiles on _all_ of the compilers.
Does this make sense? Is the Sun compiler out of date with respect to
instantiation rules? Is is "undefined" as to how this should work?
Thanks for any info,
Damon Lipparelli
(lipp@primuscorp.com)
---
LBJ, LBJ, how many JOKES did you tell today??!
---
[ To submit articles: try just posting with your news-reader.
If that fails, use mailto:std-c++@ncar.ucar.edu
FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu.
]