Topic: Template Creation and Namespaces
Author: "Patrick Hurley" <spam@hurleyhome.com>
Date: 2000/02/04 Raw View
Hyman Rosen <hymie@prolifics.com> wrote in message
news:t7g0vb2kg7.fsf@calumny.jyacc.com...
> According to 14.6.3, non-dependent names are bound at the point of
> use, so test would be looked up at this point, and not found. This
> code should not compile.
What is meant by point of use? If that mean when I first use the template,
then my call to test is defined, due to the using directives, and the code
should print B. At least that is how I would interpret the word use.
pth
namespace A { void test () { cout << "A" << endl; } }
namespace B { void test () { cout << "B" << endl; }}
template <class T> class sideffect {
public: void tryit () { test (); }
};
using namespace A;
// using namespace B;
int main () {
using B::test;
sideffect<int> a;
a.tryit ();
return 0;
}
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Hyman Rosen <hymie@prolifics.com>
Date: 2000/02/04 Raw View
"Patrick Hurley" <spam@hurleyhome.com> writes:
> What is meant by point of use? If that mean when I first use the template,
> then my call to test is defined, due to the using directives, and the code
> should print B. At least that is how I would interpret the word use.
It's the point where the template definition appears.
Look at the example in 14.6.3.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Patrick Hurley" <spam@hurleyhome.com>
Date: 2000/02/02 Raw View
Ok maybe I should buy the standard, but would you please help me with this
piece of code? I would have expected it to fail, as test does not exist in
the default namespace. If it should work, I would expect it to pick up
locallly defined use of B. In my available compilers this is not the case. I
get the A::test usage which was globally defined.
tia pth
#include <iostream>
using std::cout;
using std::endl;
namespace A {
void test () {
cout << "A" << endl;
}
}
namespace B {
void test () {
cout << "B" << endl;
}
}
template <class T>
class sideffect {
public:
void tryit () {
test ();
}
private:
};
using namespace A;
// using namespace B;
int main () {
using B::test;
sideffect<int> a;
a.tryit ();
return 0;
}
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]