enum e {E};
template <e f> class b {};
template <e f> class A : std::pair<int, b<E> >
{
ÿÿÿÿÿÿÿ A() : pair() {}
};
template <e f> class B : std::pair<int, b<f> >
{
ÿÿÿÿÿÿÿ B() : pair() {}
};
Time to get more explicit? Seems to work wrt:
_________________________
#include <utility>
#include <iostream>
enum e {E};
template <e f> class b {};
template <e f> class A : std::pair<int, b<E> >
{
ÿÿÿÿÿÿÿ A() : std::pair<int, b<E> >() {}
};
template <e f> class B : std::pair<int, b<f> >
{
ÿÿÿÿÿÿÿ B() : std::pair<int, b<f> >() {}
};
int main()
{
ÿÿÿ std::cout << "Hello..." << std::endl;
ÿÿÿ return 0;
}
_________________________
Does that help?
On 02/12/2025 21:06, Chris M. Thomasson wrote:[...]
Time to get more explicit? Seems to work wrt:
_________________________
_________________________
Does that help?
Yes, It gets me out of my hole. But... Why do I need to be explicit in
class B, but not in class A? The only difference is that the second pair parameter is variable not fixed.
, the compiler cakes its pants.
Not exactly sure. Humm. I noticed that wrt the following: _____________________
#include <utility>
#include <iostream>
enum e {E};
template <e f> class b {};
template <typename f> class A : std::pair<int, b<E> >
{
ÿÿÿÿÿÿÿ A() : std::pair<int, b<E> >() {}
};
template <e f> class B : std::pair<int, b<f> >
{
ÿÿÿÿÿÿÿ B() : std::pair<int, b<f> >() {}
};
int main()
{
std::cout << "Hello..." << std::endl;
ÿÿÿ return 0;
}
_____________________
works (aka compiles), but if I put a typename for e in class B wrt <e
, the compiler cakes its pants.
///////////////////////////////////////////////////
#include <utility>
enum e {E};
template <e f> class b {};
template <e f> class A : std::pair<int, b<E> >
{
ÿÿÿÿÿÿÿ A() : pair() {}
};
template <e f> class B : std::pair<int, b<f> >
{
ÿÿÿÿÿÿÿ B() : pair() {}
};
On 02/12/2025 21:43, Chris M. Thomasson wrote:[...]
Not exactly sure. Humm. I noticed that wrt the following:
It occurred to me later - what compiler are you using? I've tried G++
and clang++ on Unix. I don't have MS compiler available.
And I just realised I don't need that pair, just the templated base
class b to show the problem.
It is the same issue as in this example
ÿ template <typename T> struct B { int x; };
ÿ template <typename T> struct D : B<T> {
ÿÿÿ D() {
ÿÿÿÿÿ x = 5; // error: 'x' was not declared in this scope
ÿÿÿ }
ÿ };
When compiling the subclass `D`, unqualified name lookup is not
performed in base classes that depend on template parameters of `D`. For which reason unqualified name `x` (supposedly inherited from base
`B<T>`) is not visible from members of `D`.
In your case the same thing happens.
The unqualified name `pair` you refer to in your code is an _injected_
name inside base class `std::pair<>`, i.e. it is actually a member of `std::pair`. In order to find that `pair` the compiler has to perform unqualified lookup inside the base class `std::pair<>`.
But in the second case the unqualified lookup inside is not performed
for reasons I described above. Which is why unqualified name `pair` is
not found.
If you use a qualified name, the problem will go away, albeit in this
case you will also have to reiterate the template arguments
ÿ template <e f> class B : std::pair<int, b<f>>
ÿ {
ÿÿÿ B() : std::pair<int, b<f>>() {}
ÿ };
If you use a qualified name, the problem will go away, albeit in this
case you will also have to reiterate the template arguments
ÿ template <e f> class B : std::pair<int, b<f>>
ÿ {
ÿÿÿ B() : std::pair<int, b<f>>() {}
ÿ };
On 03/12/2025 12:10, Andrey Tarasevich wrote:
<snip>
If you use a qualified name, the problem will go away, albeit in this
case you will also have to reiterate the template arguments
ÿÿ template <e f> class B : std::pair<int, b<f>>
ÿÿ {
ÿÿÿÿ B() : std::pair<int, b<f>>() {}
ÿÿ };
"Problem" you say. Is this a compiler bug in both Gnu and Clang
compilers, or is it supposed to be like it?
In your case it just happens to involve so called "injected class name", which is another fairly obscure C++ topic
ÿ https://en.cppreference.com/w/cpp/language/injected-class-name.htm
| Sysop: | Tetrazocine |
|---|---|
| Location: | Melbourne, VIC, Australia |
| Users: | 14 |
| Nodes: | 8 (0 / 8) |
| Uptime: | 158:01:38 |
| Calls: | 185 |
| Files: | 21,502 |
| Messages: | 78,912 |