Re: How `export' could be useful
Walter Bright <walter@digitalmars-nospamm.com> writes:
David Abrahams wrote:
Walter Bright <walter@digitalmars-nospamm.com> writes:
where C++ got bizarre is when weird rules were added
like you cannot redeclare template parameters even within nested local
scopes, base member names are not found,...
of course they are found, if the base is non-dependent,
That is true, I should have mentioned that. Here's an excerpt from my
template talk at SDWest on the strange rules (example adapted from the
C++98 Standard):
int g(double d) { return 1; }
typedef double A;
template<class T> B
{
typedef int A;
};
template<class T> struct X : B<T>
{
A a; // a has type double
int T; // error, T redeclared
int foo()
{ char T; // error, T redeclared
return g(1); // always returns 1
}
};
int g(int i) { return 2; } // this definition not seen by X
and dependent base member names _can't_ be found
There is no technical reason why they cannot be.
Of course there is. Did you see the example in my previous posting?
It looks as though you completely ignored it. Here's yet another
example (though you should really go back and look at the others,
too):
template <class T>
struct base;
template <class T>
struct derived : base<T>
{
A a; // what type does a have?
};
template <class T>
struct base<T*>
{
typedef int A;
};
template <class T, class U>
struct base<T(U)>
{
typedef char* A;
};
I had to actually *break* finding them in DMC++ so it would be
standard conformant.
Then, IMO, you were missing something to begin with.
Furthermore, in D, the template lookup rules
actually work as one would expect. The above example code written in
D would be:
int g(double d) { return 1; }
typedef double A;
class B(T)
{
typedef int A;
}
class X(T) : B!(T)
{
A a; // a has type int
int T; // ok, T redeclared as int
int foo()
{ char T; // ok, T redeclared as char
return g(1); // always returns 2
}
};
What if A specialization comes along? Does that affect whether "a"
has type int above? Or is it fixed for all time?
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]