0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

How Can I remove compile errors in C++

Last updated at Posted at 2022-06-19

6.5.2 Member name lookup [class.member.lookup] C++N4910:2022 (13) p44.cpp

There are many compile errors.

算譜(source code)

p44.cpp
// C++N4910 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/n4910.pdf
const char * msg="6.5.2 Member name lookup [class.member.lookup]  C++N4910:2022 (13) p44.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.

#include <iostream>
#include <cstdlib>
#include <cstring>

using namespace std;

//[Example 1 :
struct A { int x; }; // S(x,A) = { { A::x }, { A } }
struct B { float x; }; // S(x,B) = { { B::x }, { B } }
struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
struct D: public virtual C { }; // S(x,D) = S(x,C)
struct E: public virtual C { char x; }; // S(x,E) = { { E::x }, { E } }
struct F: public D, public E { }; // S(x,F) = S(x,E)
int main() {
F f;
f.x = 0; // OK, lookup finds E::x
}
// Example 2 :
struct V {
int v;
};
struct A {
int a;
static int s;
enum { e };
};
struct B : A, virtual V { };
struct C : A, virtual V { };
struct D : B, C { };
void f(D* pd) {
pd->v++; // OK, only one v (virtual)
pd->s++; // OK, only one s (static)
int i = pd->e; // OK, only one e (enumerator)
pd->a++; // error: ambiguous: two as in D
}
// [Example 3 :
void D::glorp() {
x++; // OK, B::x hides V::x
f(); // OK, B::f() hides V::f()
y++; // error: B::y and C’s W::y
g(); // error: B::g() and C’s W::g()
}
struct V { int f(); int x; };
struct W { int g(); int y; };
struct B : virtual V, W {
int f(); int x;
int g(); int y;
};
struct C : virtual V, W { };
struct D : B, C { void glorp(); };
// [Example 4 :
struct V { };
struct A { };
struct B : A, virtual V { };
struct C : A, virtual V { };
struct D : B, C { };
void g() {
D d;
B* pb = &d;
A* pa = &d; // error: ambiguous: C’s A or B’s A?
V* pv = &d; // OK, only one V subobject
}
// [Example 5 :
struct B1 {
void f();
static void f(int);
int i;
};
struct B2 {
void f(double);
};
struct I1: B1 { };
struct I2: B1 { };
struct D: I1, I2, B2 {
using B1::f;
using B2::f;
void g() {
f(); // Ambiguous conversion of this
f(0); // Unambiguous (static)
f(0.0); // Unambiguous (only one B2)
int B1::* mpB1 = &D::i; // Unambiguous
int D::* mpD = &D::i; // Ambiguous conversion
}
};

int main() { return sq(9);// OK, sq from module
  cout<< msg << endl;
  return EXIT_SUCCESS;
}

Script

clgc.sh
#!/bin/sh
rm $1l
rm $1g
echo "$ clang++ $1.cpp -std=03 -o $1l -I. -Wall" 
clang++ $1.cpp -std=c++03 -o $1l -I. -Wall
if [  -e $1l ]; then
./$1l 
fi
rm $1l
echo "$ clang++ $1.cpp -std=2b -o $1l -I. -Wall"
clang++ $1.cpp -std=c++2b -o $1l -I. -Wall
if [  -e $1l ]; then
./$1l
fi
echo "\r"
echo "$ g++ $1.cpp -std=03 -o $1g -I. -Wall"
g++ $1.cpp -std=c++03 -o $1g -I. -Wall
if [ -e $1g ]; then
./$1g
fi
rm $1g
echo "\r"
echo "$ g++ $1.cpp -std=2b -o $1g -I. -Wall"
g++ $1.cpp -std=c++2b -o $1g -I. -Wall
if [ -e $1g ]; then
./$1g 
fi

編纂・実行結果(compile and go)

clgc.sh
# ./clgc.sh p44
rm: cannot remove 'p44l': No such file or directory
rm: cannot remove 'p44g': No such file or directory
$ clang++ p44.cpp -std=03 -o p44l -I. -Wall
p44.cpp:27:8: error: redefinition of 'A'
struct A {
       ^
p44.cpp:13:8: note: previous definition is here
struct A { int x; }; // S(x,A) = { { A::x }, { A } }
       ^
p44.cpp:32:8: error: redefinition of 'B'
struct B : A, virtual V { };
       ^
p44.cpp:14:8: note: previous definition is here
struct B { float x; }; // S(x,B) = { { B::x }, { B } }
       ^
p44.cpp:33:8: error: redefinition of 'C'
struct C : A, virtual V { };
       ^
p44.cpp:15:8: note: previous definition is here
struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
       ^
p44.cpp:34:8: error: redefinition of 'D'
struct D : B, C { };
       ^
p44.cpp:16:8: note: previous definition is here
struct D: public virtual C { }; // S(x,D) = S(x,C)
       ^
p44.cpp:36:5: error: no member named 'v' in 'D'
pd->v++; // OK, only one v (virtual)
~~  ^
p44.cpp:37:5: error: no member named 's' in 'D'
pd->s++; // OK, only one s (static)
~~  ^
p44.cpp:38:13: error: no member named 'e' in 'D'
int i = pd->e; // OK, only one e (enumerator)
        ~~  ^
p44.cpp:39:5: error: no member named 'a' in 'D'
pd->a++; // error: ambiguous: two as in D
~~  ^
p44.cpp:42:9: error: out-of-line definition of 'glorp' does not match any declaration in 'D'
void D::glorp() {
        ^~~~~
p44.cpp:43:1: error: member 'x' found in multiple base classes of different types
x++; // OK, B::x hides V::x
^
p44.cpp:13:16: note: member found by ambiguous name lookup
struct A { int x; }; // S(x,A) = { { A::x }, { A } }
               ^
p44.cpp:14:18: note: member found by ambiguous name lookup
struct B { float x; }; // S(x,B) = { { B::x }, { B } }
                 ^
p44.cpp:44:1: error: no matching function for call to 'f'
f(); // OK, B::f() hides V::f()
^
p44.cpp:35:6: note: candidate function not viable: requires single argument 'pd', but no arguments were provided
void f(D* pd) {
     ^
p44.cpp:45:1: error: use of undeclared identifier 'y'
y++; // error: B::y and C’s W::y
^
p44.cpp:46:1: error: use of undeclared identifier 'g'
g(); // error: B::g() and C’s W::g()
^
p44.cpp:48:8: error: redefinition of 'V'
struct V { int f(); int x; };
       ^
p44.cpp:24:8: note: previous definition is here
struct V {
       ^
p44.cpp:50:8: error: redefinition of 'B'
struct B : virtual V, W {
       ^
p44.cpp:14:8: note: previous definition is here
struct B { float x; }; // S(x,B) = { { B::x }, { B } }
       ^
p44.cpp:54:8: error: redefinition of 'C'
struct C : virtual V, W { };
       ^
p44.cpp:15:8: note: previous definition is here
struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
       ^
p44.cpp:55:8: error: redefinition of 'D'
struct D : B, C { void glorp(); };
       ^
p44.cpp:16:8: note: previous definition is here
struct D: public virtual C { }; // S(x,D) = S(x,C)
       ^
p44.cpp:57:8: error: redefinition of 'V'
struct V { };
       ^
p44.cpp:24:8: note: previous definition is here
struct V {
       ^
p44.cpp:58:8: error: redefinition of 'A'
struct A { };
       ^
p44.cpp:13:8: note: previous definition is here
struct A { int x; }; // S(x,A) = { { A::x }, { A } }
       ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
rm: cannot remove 'p44l': No such file or directory
$ clang++ p44.cpp -std=2b -o p44l -I. -Wall
p44.cpp:27:8: error: redefinition of 'A'
struct A {
       ^
p44.cpp:13:8: note: previous definition is here
struct A { int x; }; // S(x,A) = { { A::x }, { A } }
       ^
p44.cpp:32:8: error: redefinition of 'B'
struct B : A, virtual V { };
       ^
p44.cpp:14:8: note: previous definition is here
struct B { float x; }; // S(x,B) = { { B::x }, { B } }
       ^
p44.cpp:33:8: error: redefinition of 'C'
struct C : A, virtual V { };
       ^
p44.cpp:15:8: note: previous definition is here
struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
       ^
p44.cpp:34:8: error: redefinition of 'D'
struct D : B, C { };
       ^
p44.cpp:16:8: note: previous definition is here
struct D: public virtual C { }; // S(x,D) = S(x,C)
       ^
p44.cpp:36:5: error: no member named 'v' in 'D'
pd->v++; // OK, only one v (virtual)
~~  ^
p44.cpp:37:5: error: no member named 's' in 'D'
pd->s++; // OK, only one s (static)
~~  ^
p44.cpp:38:13: error: no member named 'e' in 'D'
int i = pd->e; // OK, only one e (enumerator)
        ~~  ^
p44.cpp:39:5: error: no member named 'a' in 'D'
pd->a++; // error: ambiguous: two as in D
~~  ^
p44.cpp:42:9: error: out-of-line definition of 'glorp' does not match any declaration in 'D'
void D::glorp() {
        ^~~~~
p44.cpp:43:1: error: member 'x' found in multiple base classes of different types
x++; // OK, B::x hides V::x
^
p44.cpp:13:16: note: member found by ambiguous name lookup
struct A { int x; }; // S(x,A) = { { A::x }, { A } }
               ^
p44.cpp:14:18: note: member found by ambiguous name lookup
struct B { float x; }; // S(x,B) = { { B::x }, { B } }
                 ^
p44.cpp:44:1: error: no matching function for call to 'f'
f(); // OK, B::f() hides V::f()
^
p44.cpp:35:6: note: candidate function not viable: requires single argument 'pd', but no arguments were provided
void f(D* pd) {
     ^
p44.cpp:45:1: error: use of undeclared identifier 'y'
y++; // error: B::y and C’s W::y
^
p44.cpp:46:1: error: use of undeclared identifier 'g'
g(); // error: B::g() and C’s W::g()
^
p44.cpp:48:8: error: redefinition of 'V'
struct V { int f(); int x; };
       ^
p44.cpp:24:8: note: previous definition is here
struct V {
       ^
p44.cpp:50:8: error: redefinition of 'B'
struct B : virtual V, W {
       ^
p44.cpp:14:8: note: previous definition is here
struct B { float x; }; // S(x,B) = { { B::x }, { B } }
       ^
p44.cpp:54:8: error: redefinition of 'C'
struct C : virtual V, W { };
       ^
p44.cpp:15:8: note: previous definition is here
struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
       ^
p44.cpp:55:8: error: redefinition of 'D'
struct D : B, C { void glorp(); };
       ^
p44.cpp:16:8: note: previous definition is here
struct D: public virtual C { }; // S(x,D) = S(x,C)
       ^
p44.cpp:57:8: error: redefinition of 'V'
struct V { };
       ^
p44.cpp:24:8: note: previous definition is here
struct V {
       ^
p44.cpp:58:8: error: redefinition of 'A'
struct A { };
       ^
p44.cpp:13:8: note: previous definition is here
struct A { int x; }; // S(x,A) = { { A::x }, { A } }
       ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

$ g++ p44.cpp -std=03 -o p44g -I. -Wall
p44.cpp: In function 'int main()':
p44.cpp:21:3: error: request for member 'x' is ambiguous
   21 | f.x = 0; // OK, lookup finds E::x
      |   ^
p44.cpp:14:18: note: candidates are: 'float B::x'
   14 | struct B { float x; }; // S(x,B) = { { B::x }, { B } }
      |                  ^
p44.cpp:13:16: note:                 'int A::x'
   13 | struct A { int x; }; // S(x,A) = { { A::x }, { A } }
      |                ^
p44.cpp: At global scope:
p44.cpp:27:8: error: redefinition of 'struct A'
   27 | struct A {
      |        ^
p44.cpp:13:8: note: previous definition of 'struct A'
   13 | struct A { int x; }; // S(x,A) = { { A::x }, { A } }
      |        ^
p44.cpp:32:8: error: redefinition of 'struct B'
   32 | struct B : A, virtual V { };
      |        ^
p44.cpp:14:8: note: previous definition of 'struct B'
   14 | struct B { float x; }; // S(x,B) = { { B::x }, { B } }
      |        ^
p44.cpp:33:8: error: redefinition of 'struct C'
   33 | struct C : A, virtual V { };
      |        ^
p44.cpp:15:8: note: previous definition of 'struct C'
   15 | struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
      |        ^
p44.cpp:34:8: error: redefinition of 'struct D'
   34 | struct D : B, C { };
      |        ^
p44.cpp:16:8: note: previous definition of 'struct D'
   16 | struct D: public virtual C { }; // S(x,D) = S(x,C)
      |        ^
p44.cpp: In function 'void f(D*)':
p44.cpp:36:5: error: 'struct D' has no member named 'v'
   36 | pd->v++; // OK, only one v (virtual)
      |     ^
p44.cpp:37:5: error: 'struct D' has no member named 's'
   37 | pd->s++; // OK, only one s (static)
      |     ^
p44.cpp:38:13: error: 'struct D' has no member named 'e'
   38 | int i = pd->e; // OK, only one e (enumerator)
      |             ^
p44.cpp:39:5: error: 'struct D' has no member named 'a'
   39 | pd->a++; // error: ambiguous: two as in D
      |     ^
p44.cpp:38:5: warning: unused variable 'i' [-Wunused-variable]
   38 | int i = pd->e; // OK, only one e (enumerator)
      |     ^
p44.cpp: At global scope:
p44.cpp:42:6: error: no declaration matches 'void D::glorp()'
   42 | void D::glorp() {
      |      ^
p44.cpp:42:6: note: no functions named 'void D::glorp()'
p44.cpp:16:8: note: 'struct D' defined here
   16 | struct D: public virtual C { }; // S(x,D) = S(x,C)
      |        ^
p44.cpp:48:8: error: redefinition of 'struct V'
   48 | struct V { int f(); int x; };
      |        ^
p44.cpp:24:8: note: previous definition of 'struct V'
   24 | struct V {
      |        ^
p44.cpp:50:8: error: redefinition of 'struct B'
   50 | struct B : virtual V, W {
      |        ^
p44.cpp:14:8: note: previous definition of 'struct B'
   14 | struct B { float x; }; // S(x,B) = { { B::x }, { B } }
      |        ^
p44.cpp:54:8: error: redefinition of 'struct C'
   54 | struct C : virtual V, W { };
      |        ^
p44.cpp:15:8: note: previous definition of 'struct C'
   15 | struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
      |        ^
p44.cpp:55:8: error: redefinition of 'struct D'
   55 | struct D : B, C { void glorp(); };
      |        ^
p44.cpp:16:8: note: previous definition of 'struct D'
   16 | struct D: public virtual C { }; // S(x,D) = S(x,C)
      |        ^
p44.cpp:57:8: error: redefinition of 'struct V'
   57 | struct V { };
      |        ^
p44.cpp:24:8: note: previous definition of 'struct V'
   24 | struct V {
      |        ^
p44.cpp:58:8: error: redefinition of 'struct A'
   58 | struct A { };
      |        ^
p44.cpp:13:8: note: previous definition of 'struct A'
   13 | struct A { int x; }; // S(x,A) = { { A::x }, { A } }
      |        ^
p44.cpp:59:8: error: redefinition of 'struct B'
   59 | struct B : A, virtual V { };
      |        ^
p44.cpp:14:8: note: previous definition of 'struct B'
   14 | struct B { float x; }; // S(x,B) = { { B::x }, { B } }
      |        ^
p44.cpp:60:8: error: redefinition of 'struct C'
   60 | struct C : A, virtual V { };
      |        ^
p44.cpp:15:8: note: previous definition of 'struct C'
   15 | struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
      |        ^
p44.cpp:61:8: error: redefinition of 'struct D'
   61 | struct D : B, C { };
      |        ^
p44.cpp:16:8: note: previous definition of 'struct D'
   16 | struct D: public virtual C { }; // S(x,D) = S(x,C)
      |        ^
p44.cpp: In function 'void g()':
p44.cpp:66:9: error: cannot convert 'D*' to 'V*' in initialization
   66 | V* pv = &d; // OK, only one V subobject
      |         ^~
      |         |
      |         D*
p44.cpp:64:4: warning: unused variable 'pb' [-Wunused-variable]
   64 | B* pb = &d;
      |    ^~
p44.cpp:65:4: warning: unused variable 'pa' [-Wunused-variable]
   65 | A* pa = &d; // error: ambiguous: C’s A or B’s A?
      |    ^~
p44.cpp:66:4: warning: unused variable 'pv' [-Wunused-variable]
   66 | V* pv = &d; // OK, only one V subobject
      |    ^~
p44.cpp: At global scope:
p44.cpp:79:8: error: redefinition of 'struct D'
   79 | struct D: I1, I2, B2 {
      |        ^
p44.cpp:16:8: note: previous definition of 'struct D'
   16 | struct D: public virtual C { }; // S(x,D) = S(x,C)
      |        ^
p44.cpp:91:5: error: redefinition of 'int main()'
   91 | int main() { return sq(9);// OK, sq from module
      |     ^~~~
p44.cpp:19:5: note: 'int main()' previously defined here
   19 | int main() {
      |     ^~~~
p44.cpp: In function 'int main()':
p44.cpp:91:21: error: 'sq' was not declared in this scope
   91 | int main() { return sq(9);// OK, sq from module
      |                     ^~
rm: cannot remove 'p44g': No such file or directory

$ g++ p44.cpp -std=2b -o p44g -I. -Wall
p44.cpp: In function 'int main()':
p44.cpp:21:3: error: request for member 'x' is ambiguous
   21 | f.x = 0; // OK, lookup finds E::x
      |   ^
p44.cpp:14:18: note: candidates are: 'float B::x'
   14 | struct B { float x; }; // S(x,B) = { { B::x }, { B } }
      |                  ^
p44.cpp:13:16: note:                 'int A::x'
   13 | struct A { int x; }; // S(x,A) = { { A::x }, { A } }
      |                ^
p44.cpp: At global scope:
p44.cpp:27:8: error: redefinition of 'struct A'
   27 | struct A {
      |        ^
p44.cpp:13:8: note: previous definition of 'struct A'
   13 | struct A { int x; }; // S(x,A) = { { A::x }, { A } }
      |        ^
p44.cpp:32:8: error: redefinition of 'struct B'
   32 | struct B : A, virtual V { };
      |        ^
p44.cpp:14:8: note: previous definition of 'struct B'
   14 | struct B { float x; }; // S(x,B) = { { B::x }, { B } }
      |        ^
p44.cpp:33:8: error: redefinition of 'struct C'
   33 | struct C : A, virtual V { };
      |        ^
p44.cpp:15:8: note: previous definition of 'struct C'
   15 | struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
      |        ^
p44.cpp:34:8: error: redefinition of 'struct D'
   34 | struct D : B, C { };
      |        ^
p44.cpp:16:8: note: previous definition of 'struct D'
   16 | struct D: public virtual C { }; // S(x,D) = S(x,C)
      |        ^
p44.cpp: In function 'void f(D*)':
p44.cpp:36:5: error: 'struct D' has no member named 'v'
   36 | pd->v++; // OK, only one v (virtual)
      |     ^
p44.cpp:37:5: error: 'struct D' has no member named 's'
   37 | pd->s++; // OK, only one s (static)
      |     ^
p44.cpp:38:13: error: 'struct D' has no member named 'e'
   38 | int i = pd->e; // OK, only one e (enumerator)
      |             ^
p44.cpp:39:5: error: 'struct D' has no member named 'a'
   39 | pd->a++; // error: ambiguous: two as in D
      |     ^
p44.cpp:38:5: warning: unused variable 'i' [-Wunused-variable]
   38 | int i = pd->e; // OK, only one e (enumerator)
      |     ^
p44.cpp: At global scope:
p44.cpp:42:6: error: no declaration matches 'void D::glorp()'
   42 | void D::glorp() {
      |      ^
p44.cpp:42:6: note: no functions named 'void D::glorp()'
p44.cpp:16:8: note: 'struct D' defined here
   16 | struct D: public virtual C { }; // S(x,D) = S(x,C)
      |        ^
p44.cpp:48:8: error: redefinition of 'struct V'
   48 | struct V { int f(); int x; };
      |        ^
p44.cpp:24:8: note: previous definition of 'struct V'
   24 | struct V {
      |        ^
p44.cpp:50:8: error: redefinition of 'struct B'
   50 | struct B : virtual V, W {
      |        ^
p44.cpp:14:8: note: previous definition of 'struct B'
   14 | struct B { float x; }; // S(x,B) = { { B::x }, { B } }
      |        ^
p44.cpp:54:8: error: redefinition of 'struct C'
   54 | struct C : virtual V, W { };
      |        ^
p44.cpp:15:8: note: previous definition of 'struct C'
   15 | struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
      |        ^
p44.cpp:55:8: error: redefinition of 'struct D'
   55 | struct D : B, C { void glorp(); };
      |        ^
p44.cpp:16:8: note: previous definition of 'struct D'
   16 | struct D: public virtual C { }; // S(x,D) = S(x,C)
      |        ^
p44.cpp:57:8: error: redefinition of 'struct V'
   57 | struct V { };
      |        ^
p44.cpp:24:8: note: previous definition of 'struct V'
   24 | struct V {
      |        ^
p44.cpp:58:8: error: redefinition of 'struct A'
   58 | struct A { };
      |        ^
p44.cpp:13:8: note: previous definition of 'struct A'
   13 | struct A { int x; }; // S(x,A) = { { A::x }, { A } }
      |        ^
p44.cpp:59:8: error: redefinition of 'struct B'
   59 | struct B : A, virtual V { };
      |        ^
p44.cpp:14:8: note: previous definition of 'struct B'
   14 | struct B { float x; }; // S(x,B) = { { B::x }, { B } }
      |        ^
p44.cpp:60:8: error: redefinition of 'struct C'
   60 | struct C : A, virtual V { };
      |        ^
p44.cpp:15:8: note: previous definition of 'struct C'
   15 | struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
      |        ^
p44.cpp:61:8: error: redefinition of 'struct D'
   61 | struct D : B, C { };
      |        ^
p44.cpp:16:8: note: previous definition of 'struct D'
   16 | struct D: public virtual C { }; // S(x,D) = S(x,C)
      |        ^
p44.cpp: In function 'void g()':
p44.cpp:66:9: error: cannot convert 'D*' to 'V*' in initialization
   66 | V* pv = &d; // OK, only one V subobject
      |         ^~
      |         |
      |         D*
p44.cpp:64:4: warning: unused variable 'pb' [-Wunused-variable]
   64 | B* pb = &d;
      |    ^~
p44.cpp:65:4: warning: unused variable 'pa' [-Wunused-variable]
   65 | A* pa = &d; // error: ambiguous: C’s A or B’s A?
      |    ^~
p44.cpp:66:4: warning: unused variable 'pv' [-Wunused-variable]
   66 | V* pv = &d; // OK, only one V subobject
      |    ^~
p44.cpp: At global scope:
p44.cpp:79:8: error: redefinition of 'struct D'
   79 | struct D: I1, I2, B2 {
      |        ^
p44.cpp:16:8: note: previous definition of 'struct D'
   16 | struct D: public virtual C { }; // S(x,D) = S(x,C)
      |        ^
p44.cpp:91:5: error: redefinition of 'int main()'
   91 | int main() { return sq(9);// OK, sq from module
      |     ^~~~
p44.cpp:19:5: note: 'int main()' previously defined here
   19 | int main() {
      |     ^~~~
p44.cpp: In function 'int main()':
p44.cpp:91:21: error: 'sq' was not declared in this scope
   91 | int main() { return sq(9);// OK, sq from module
      |   


検討事項(agenda)

Change the name of the variables.

算譜(source code)

p44.cpp
// C++N4910 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/n4910.pdf
const char * msg="6.5.2 Member name lookup [class.member.lookup]  C++N4910:2022 (13) p44.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.

#include <iostream>
#include <cstdlib>
#include <cstring>

using namespace std;

//[Example 1 :
struct A { int x; }; // S(x,A) = { { A::x }, { A } }
struct B { float x; }; // S(x,B) = { { B::x }, { B } }
struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
struct D: public virtual C { }; // S(x,D) = S(x,C)
struct E: public virtual C { char x; }; // S(x,E) = { { E::x }, { E } }
struct F: public D, public E { }; // S(x,F) = S(x,E)
int main() {
F f;
f.x = 0; // OK, lookup finds E::x
}
// Example 2 :
struct V {
int v;
};
struct A2 {
int a;
static int s;
enum { e };
};
struct B2 : A2, virtual V { };
struct C2 : A2, virtual V { };
struct D2 : B2, C2 { };
void f(D2* pd) {
pd->v++; // OK, only one v (virtual)
pd->s++; // OK, only one s (static)
int i = pd->e; // OK, only one e (enumerator)
pd->a++; // error: ambiguous: two as in D
}
// [Example 3 :
void D3::glorp() {
x++; // OK, B::x hides V::x
f(); // OK, B::f() hides V::f()
y++; // error: B::y and C’s W::y
g(); // error: B::g() and C’s W::g()
}
struct V { int f(); int x; };
struct W { int g(); int y; };
struct B3 : virtual V, W {
int f(); int x;
int g(); int y;
};
struct C3 : virtual V, W { };
struct D3 : B3, C3 { void glorp(); };
// [Example 4 :
struct V4 { };
struct A4 { };
struct B4 : A, virtual V4 { };
struct C4 : A, virtual V4 { };
struct D4 : B4, C4 { };
void g() {
D4 d;
B4* pb = &d;
A4* pa = &d; // error: ambiguous: C’s A or B’s A?
V4* pv = &d; // OK, only one V subobject
}
// [Example 5 :
struct B1 {
void f();
static void f(int);
int i;
};
struct B2 {
void f(double);
};
struct I1: B1 { };
struct I2: B1 { };
struct D5: I1, I2, B2 {
using B1::f;
using B2::f;
void g() {
f(); // Ambiguous conversion of this
f(0); // Unambiguous (static)
f(0.0); // Unambiguous (only one B2)
int B1::* mpB1 = &D::i; // Unambiguous
int D5::* mpD = &D::i; // Ambiguous conversion
}
};

int main() { return sq(9);// OK, sq from module
  cout<< msg << endl;
  return EXIT_SUCCESS;
}

編纂・実行結果(compile and go)

bash
# ./clgc.sh p44
rm: cannot remove 'p44l': No such file or directory
rm: cannot remove 'p44g': No such file or directory
$ clang++ p44.cpp -std=03 -o p44l -I. -Wall
p44.cpp:39:5: error: non-static member 'a' found in multiple base-class subobjects of type 'A2':
    struct D2 -> struct B2 -> struct A2
    struct D2 -> struct C2 -> struct A2
pd->a++; // error: ambiguous: two as in D
    ^
p44.cpp:28:5: note: member found by ambiguous name lookup
int a;
    ^
p44.cpp:42:6: error: use of undeclared identifier 'D3'
void D3::glorp() {
     ^
p44.cpp:48:8: error: redefinition of 'V'
struct V { int f(); int x; };
       ^
p44.cpp:24:8: note: previous definition is here
struct V {
       ^
p44.cpp:65:5: error: cannot initialize a variable of type 'A4 *' with an rvalue of type 'D4 *'
A4* pa = &d; // error: ambiguous: C’s A or B’s A?
    ^    ~~
p44.cpp:74:8: error: redefinition of 'B2'
struct B2 {
       ^
p44.cpp:32:8: note: previous definition is here
struct B2 : A2, virtual V { };
       ^
p44.cpp:81:7: error: no member named 'f' in 'B2'; did you mean '::D5::f'?
using B2::f;
      ^~~~~
      ::D5::f
p44.cpp:80:11: note: '::D5::f' declared here
using B1::f;
          ^
p44.cpp:83:1: error: ambiguous conversion from derived class 'D5' to base class 'B1':
    struct D5 -> struct I1 -> struct B1
    struct D5 -> struct I2 -> struct B1
f(); // Ambiguous conversion of this
^
p44.cpp:86:22: error: no member named 'i' in 'D'
int B1::* mpB1 = &D::i; // Unambiguous
                  ~~~^
p44.cpp:87:21: error: no member named 'i' in 'D'
int D5::* mpD = &D::i; // Ambiguous conversion
                 ~~~^
p44.cpp:91:5: error: redefinition of 'main'
int main() { return sq(9);// OK, sq from module
    ^
p44.cpp:19:5: note: previous definition is here
int main() {
    ^
p44.cpp:91:21: error: use of undeclared identifier 'sq'
int main() { return sq(9);// OK, sq from module
                    ^
11 errors generated.
rm: cannot remove 'p44l': No such file or directory
$ clang++ p44.cpp -std=2b -o p44l -I. -Wall
p44.cpp:39:5: error: non-static member 'a' found in multiple base-class subobjects of type 'A2':
    struct D2 -> struct B2 -> struct A2
    struct D2 -> struct C2 -> struct A2
pd->a++; // error: ambiguous: two as in D
    ^
p44.cpp:28:5: note: member found by ambiguous name lookup
int a;
    ^
p44.cpp:42:6: error: use of undeclared identifier 'D3'
void D3::glorp() {
     ^
p44.cpp:48:8: error: redefinition of 'V'
struct V { int f(); int x; };
       ^
p44.cpp:24:8: note: previous definition is here
struct V {
       ^
p44.cpp:65:5: error: cannot initialize a variable of type 'A4 *' with an rvalue of type 'D4 *'
A4* pa = &d; // error: ambiguous: C’s A or B’s A?
    ^    ~~
p44.cpp:74:8: error: redefinition of 'B2'
struct B2 {
       ^
p44.cpp:32:8: note: previous definition is here
struct B2 : A2, virtual V { };
       ^
p44.cpp:81:7: error: no member named 'f' in 'B2'; did you mean '::D5::f'?
using B2::f;
      ^~~~~
      ::D5::f
p44.cpp:80:11: note: '::D5::f' declared here
using B1::f;
          ^
p44.cpp:83:1: error: ambiguous conversion from derived class 'D5' to base class 'B1':
    struct D5 -> struct I1 -> struct B1
    struct D5 -> struct I2 -> struct B1
f(); // Ambiguous conversion of this
^
p44.cpp:86:22: error: no member named 'i' in 'D'
int B1::* mpB1 = &D::i; // Unambiguous
                  ~~~^
p44.cpp:87:21: error: no member named 'i' in 'D'
int D5::* mpD = &D::i; // Ambiguous conversion
                 ~~~^
p44.cpp:91:5: error: redefinition of 'main'
int main() { return sq(9);// OK, sq from module
    ^
p44.cpp:19:5: note: previous definition is here
int main() {
    ^
p44.cpp:91:21: error: use of undeclared identifier 'sq'
int main() { return sq(9);// OK, sq from module
                    ^
11 errors generated.

$ g++ p44.cpp -std=03 -o p44g -I. -Wall
p44.cpp: In function 'int main()':
p44.cpp:21:3: error: request for member 'x' is ambiguous
   21 | f.x = 0; // OK, lookup finds E::x
      |   ^
p44.cpp:14:18: note: candidates are: 'float B::x'
   14 | struct B { float x; }; // S(x,B) = { { B::x }, { B } }
      |                  ^
p44.cpp:13:16: note:                 'int A::x'
   13 | struct A { int x; }; // S(x,A) = { { A::x }, { A } }
      |                ^
p44.cpp: In function 'void f(D2*)':
p44.cpp:39:5: error: request for member 'a' is ambiguous
   39 | pd->a++; // error: ambiguous: two as in D
      |     ^
p44.cpp:28:5: note: candidates are: 'int A2::a'
   28 | int a;
      |     ^
p44.cpp:28:5: note:                 'int A2::a'
p44.cpp:38:5: warning: unused variable 'i' [-Wunused-variable]
   38 | int i = pd->e; // OK, only one e (enumerator)
      |     ^
p44.cpp: At global scope:
p44.cpp:42:6: error: 'D3' has not been declared
   42 | void D3::glorp() {
      |      ^~
p44.cpp: In function 'void glorp()':
p44.cpp:43:1: error: 'x' was not declared in this scope
   43 | x++; // OK, B::x hides V::x
      | ^
p44.cpp:44:2: error: too few arguments to function 'void f(D2*)'
   44 | f(); // OK, B::f() hides V::f()
      | ~^~
p44.cpp:35:6: note: declared here
   35 | void f(D2* pd) {
      |      ^
p44.cpp:45:1: error: 'y' was not declared in this scope
   45 | y++; // error: B::y and C’s W::y
      | ^
p44.cpp:46:1: error: 'g' was not declared in this scope
   46 | g(); // error: B::g() and C’s W::g()
      | ^
p44.cpp: At global scope:
p44.cpp:48:8: error: redefinition of 'struct V'
   48 | struct V { int f(); int x; };
      |        ^
p44.cpp:24:8: note: previous definition of 'struct V'
   24 | struct V {
      |        ^
p44.cpp: In function 'void g()':
p44.cpp:65:10: error: cannot convert 'D4*' to 'A4*' in initialization
   65 | A4* pa = &d; // error: ambiguous: C’s A or B’s A?
      |          ^~
      |          |
      |          D4*
p44.cpp:64:5: warning: unused variable 'pb' [-Wunused-variable]
   64 | B4* pb = &d;
      |     ^~
p44.cpp:65:5: warning: unused variable 'pa' [-Wunused-variable]
   65 | A4* pa = &d; // error: ambiguous: C’s A or B’s A?
      |     ^~
p44.cpp:66:5: warning: unused variable 'pv' [-Wunused-variable]
   66 | V4* pv = &d; // OK, only one V subobject
      |     ^~
p44.cpp: At global scope:
p44.cpp:74:8: error: redefinition of 'struct B2'
   74 | struct B2 {
      |        ^~
p44.cpp:32:8: note: previous definition of 'struct B2'
   32 | struct B2 : A2, virtual V { };
      |        ^~
p44.cpp:81:11: error: 'f' has not been declared in 'struct B2'
   81 | using B2::f;
      |           ^
p44.cpp: In member function 'void D5::g()':
p44.cpp:83:2: error: 'B1' is an ambiguous base of 'D5'
   83 | f(); // Ambiguous conversion of this
      | ~^~
p44.cpp:86:22: error: 'i' is not a member of 'D'
   86 | int B1::* mpB1 = &D::i; // Unambiguous
      |                      ^
p44.cpp:87:21: error: 'i' is not a member of 'D'
   87 | int D5::* mpD = &D::i; // Ambiguous conversion
      |                     ^
p44.cpp:86:11: warning: unused variable 'mpB1' [-Wunused-variable]
   86 | int B1::* mpB1 = &D::i; // Unambiguous
      |           ^~~~
p44.cpp:87:11: warning: unused variable 'mpD' [-Wunused-variable]
   87 | int D5::* mpD = &D::i; // Ambiguous conversion
      |           ^~~
p44.cpp: At global scope:
p44.cpp:91:5: error: redefinition of 'int main()'
   91 | int main() { return sq(9);// OK, sq from module
      |     ^~~~
p44.cpp:19:5: note: 'int main()' previously defined here
   19 | int main() {
      |     ^~~~
p44.cpp: In function 'int main()':
p44.cpp:91:21: error: 'sq' was not declared in this scope
   91 | int main() { return sq(9);// OK, sq from module
      |                     ^~
rm: cannot remove 'p44g': No such file or directory

$ g++ p44.cpp -std=2b -o p44g -I. -Wall
p44.cpp: In function 'int main()':
p44.cpp:21:3: error: request for member 'x' is ambiguous
   21 | f.x = 0; // OK, lookup finds E::x
      |   ^
p44.cpp:14:18: note: candidates are: 'float B::x'
   14 | struct B { float x; }; // S(x,B) = { { B::x }, { B } }
      |                  ^
p44.cpp:13:16: note:                 'int A::x'
   13 | struct A { int x; }; // S(x,A) = { { A::x }, { A } }
      |                ^
p44.cpp: In function 'void f(D2*)':
p44.cpp:39:5: error: request for member 'a' is ambiguous
   39 | pd->a++; // error: ambiguous: two as in D
      |     ^
p44.cpp:28:5: note: candidates are: 'int A2::a'
   28 | int a;
      |     ^
p44.cpp:28:5: note:                 'int A2::a'
p44.cpp:38:5: warning: unused variable 'i' [-Wunused-variable]
   38 | int i = pd->e; // OK, only one e (enumerator)
      |     ^
p44.cpp: At global scope:
p44.cpp:42:6: error: 'D3' has not been declared
   42 | void D3::glorp() {
      |      ^~
p44.cpp: In function 'void glorp()':
p44.cpp:43:1: error: 'x' was not declared in this scope
   43 | x++; // OK, B::x hides V::x
      | ^
p44.cpp:44:2: error: too few arguments to function 'void f(D2*)'
   44 | f(); // OK, B::f() hides V::f()
      | ~^~
p44.cpp:35:6: note: declared here
   35 | void f(D2* pd) {
      |      ^
p44.cpp:45:1: error: 'y' was not declared in this scope
   45 | y++; // error: B::y and C’s W::y
      | ^
p44.cpp:46:1: error: 'g' was not declared in this scope
   46 | g(); // error: B::g() and C’s W::g()
      | ^
p44.cpp: At global scope:
p44.cpp:48:8: error: redefinition of 'struct V'
   48 | struct V { int f(); int x; };
      |        ^
p44.cpp:24:8: note: previous definition of 'struct V'
   24 | struct V {
      |        ^
p44.cpp: In function 'void g()':
p44.cpp:65:10: error: cannot convert 'D4*' to 'A4*' in initialization
   65 | A4* pa = &d; // error: ambiguous: C’s A or B’s A?
      |          ^~
      |          |
      |          D4*
p44.cpp:64:5: warning: unused variable 'pb' [-Wunused-variable]
   64 | B4* pb = &d;
      |     ^~
p44.cpp:65:5: warning: unused variable 'pa' [-Wunused-variable]
   65 | A4* pa = &d; // error: ambiguous: C’s A or B’s A?
      |     ^~
p44.cpp:66:5: warning: unused variable 'pv' [-Wunused-variable]
   66 | V4* pv = &d; // OK, only one V subobject
      |     ^~
p44.cpp: At global scope:
p44.cpp:74:8: error: redefinition of 'struct B2'
   74 | struct B2 {
      |        ^~
p44.cpp:32:8: note: previous definition of 'struct B2'
   32 | struct B2 : A2, virtual V { };
      |        ^~
p44.cpp:81:11: error: 'f' has not been declared in 'struct B2'
   81 | using B2::f;
      |           ^
p44.cpp: In member function 'void D5::g()':
p44.cpp:83:2: error: 'B1' is an ambiguous base of 'D5'
   83 | f(); // Ambiguous conversion of this
      | ~^~
p44.cpp:86:22: error: 'i' is not a member of 'D'
   86 | int B1::* mpB1 = &D::i; // Unambiguous
      |                      ^
p44.cpp:87:21: error: 'i' is not a member of 'D'
   87 | int D5::* mpD = &D::i; // Ambiguous conversion
      |                     ^
p44.cpp:86:11: warning: unused variable 'mpB1' [-Wunused-variable]
   86 | int B1::* mpB1 = &D::i; // Unambiguous
      |           ^~~~
p44.cpp:87:11: warning: unused variable 'mpD' [-Wunused-variable]
   87 | int D5::* mpD = &D::i; // Ambiguous conversion
      |           ^~~
p44.cpp: At global scope:
p44.cpp:91:5: error: redefinition of 'int main()'
   91 | int main() { return sq(9);// OK, sq from module
      |     ^~~~
p44.cpp:19:5: note: 'int main()' previously defined here
   19 | int main() {
      |     ^~~~
p44.cpp: In function 'int main()':
p44.cpp:91:21: error: 'sq' was not declared in this scope
   91 | int main() { return sq(9);// OK, sq from module
      |                     ^~

検討事項(agenda)

Change the variables which apeared in the error lines

算譜(source code)

p44.cpp
// C++N4910 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/n4910.pdf
const char * msg="6.5.2 Member name lookup [class.member.lookup]  C++N4910:2022 (13) p44.cpp";
// Edited by Dr. Ogawa Kiyoshi. Compile procedure and results record.

#include <iostream>
#include <cstdlib>
#include <cstring>

using namespace std;

//[Example 1 :
struct A { int x; }; // S(x,A) = { { A::x }, { A } }
struct B { float x; }; // S(x,B) = { { B::x }, { B } }
struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
struct D: public virtual C { }; // S(x,D) = S(x,C)
struct E: public virtual C { char x; }; // S(x,E) = { { E::x }, { E } }
struct F: public D, public E { }; // S(x,F) = S(x,E)
//int main() {
//F f;
//f.x = 0; // OK, lookup finds E::x
//}
// Example 2 :
struct V {
int v;
};
struct A2 {
int a;
static int s;
enum { e };
};
struct B6 : A2, virtual V { };
struct C2 : A2, virtual V { };
struct D2 : B6, C2 { };
void f(D2* pd) {
pd->v++; // OK, only one v (virtual)
pd->s++; // OK, only one s (static)
int i = pd->e; // OK, only one e (enumerator)
pd->a++; // error: ambiguous: two as in D
}
// [Example 3 :
struct V3 { int f(); int x; };
struct W { int g(); int y; };
struct B3 : virtual V3, W {
int f(); int x;
int g(); int y;
};
struct C3 : virtual V3, W { };
struct D3 : B3, C3 { void glorp(); };
void D3::glorp() {
x++; // OK, B::x hides V::x
f(); // OK, B::f() hides V::f()
y++; // error: B::y and C’s W::y
g(); // error: B::g() and C’s W::g()
}
// [Example 4 :
struct V4 { };
struct A4 { };
struct B4 : A, virtual V4 { };
struct C4 : A, virtual V4 { };
struct D4 : B4, C4 { };
void g() {
D4 d;
B4* pb = &d;
A4* pa = &d; // error: ambiguous: C’s A or B’s A?
V4* pv = &d; // OK, only one V subobject
}
// [Example 5 :
struct B1 {
void f();
static void f(int);
int i;
};
struct B2 {
void f(double);
};
struct I1: B1 { };
struct I2: B1 { };
struct D5: I1, I2, B2 {
using B1::f;
using B2::f;
void g() {
f(); // Ambiguous conversion of this
f(0); // Unambiguous (static)
f(0.0); // Unambiguous (only one B2)
int B1::* mpB1 = &D5::i; // Unambiguous
int D5::* mpD5 = &D5::i; // Ambiguous conversion
}
};

int main() { return sq(9);// OK, sq from module
  F f;
  f.x = 0; // Ok, lookup finds E::x
  cout<< msg << endl;
  return EXIT_SUCCESS;
}

編纂・実行結果(compile and go)

bash
# ./clgc.sh p44
rm: cannot remove 'p44l': No such file or directory
rm: cannot remove 'p44g': No such file or directory
$ clang++ p44.cpp -std=03 -o p44l -I. -Wall
p44.cpp:39:5: error: non-static member 'a' found in multiple base-class subobjects of type 'A2':
    struct D2 -> struct B6 -> struct A2
    struct D2 -> struct C2 -> struct A2
pd->a++; // error: ambiguous: two as in D
    ^
p44.cpp:28:5: note: member found by ambiguous name lookup
int a;
    ^
p44.cpp:53:1: error: member 'y' found in multiple base classes of different types
y++; // error: B::y and C’s W::y
^
p44.cpp:46:14: note: member found by ambiguous name lookup
int g(); int y;
             ^
p44.cpp:43:25: note: member found by ambiguous name lookup
struct W { int g(); int y; };
                        ^
p44.cpp:54:1: error: member 'g' found in multiple base classes of different types
g(); // error: B::g() and C’s W::g()
^
p44.cpp:46:5: note: member found by ambiguous name lookup
int g(); int y;
    ^
p44.cpp:43:16: note: member found by ambiguous name lookup
struct W { int g(); int y; };
               ^
p44.cpp:65:5: error: cannot initialize a variable of type 'A4 *' with an rvalue of type 'D4 *'
A4* pa = &d; // error: ambiguous: C’s A or B’s A?
    ^    ~~
p44.cpp:83:1: error: ambiguous conversion from derived class 'D5' to base class 'B1':
    struct D5 -> struct I1 -> struct B1
    struct D5 -> struct I2 -> struct B1
f(); // Ambiguous conversion of this
^
p44.cpp:86:23: error: non-static member 'i' found in multiple base-class subobjects of type 'B1':
    struct D5 -> struct I1 -> struct B1
    struct D5 -> struct I2 -> struct B1
int B1::* mpB1 = &D5::i; // Unambiguous
                  ~~~~^
p44.cpp:72:5: note: member found by ambiguous name lookup
int i;
    ^
p44.cpp:87:23: error: non-static member 'i' found in multiple base-class subobjects of type 'B1':
    struct D5 -> struct I1 -> struct B1
    struct D5 -> struct I2 -> struct B1
int D5::* mpD5 = &D5::i; // Ambiguous conversion
                  ~~~~^
p44.cpp:72:5: note: member found by ambiguous name lookup
int i;
    ^
p44.cpp:91:21: error: use of undeclared identifier 'sq'
int main() { return sq(9);// OK, sq from module
                    ^
8 errors generated.
rm: cannot remove 'p44l': No such file or directory
$ clang++ p44.cpp -std=2b -o p44l -I. -Wall
p44.cpp:39:5: error: non-static member 'a' found in multiple base-class subobjects of type 'A2':
    struct D2 -> struct B6 -> struct A2
    struct D2 -> struct C2 -> struct A2
pd->a++; // error: ambiguous: two as in D
    ^
p44.cpp:28:5: note: member found by ambiguous name lookup
int a;
    ^
p44.cpp:53:1: error: member 'y' found in multiple base classes of different types
y++; // error: B::y and C’s W::y
^
p44.cpp:46:14: note: member found by ambiguous name lookup
int g(); int y;
             ^
p44.cpp:43:25: note: member found by ambiguous name lookup
struct W { int g(); int y; };
                        ^
p44.cpp:54:1: error: member 'g' found in multiple base classes of different types
g(); // error: B::g() and C’s W::g()
^
p44.cpp:46:5: note: member found by ambiguous name lookup
int g(); int y;
    ^
p44.cpp:43:16: note: member found by ambiguous name lookup
struct W { int g(); int y; };
               ^
p44.cpp:65:5: error: cannot initialize a variable of type 'A4 *' with an rvalue of type 'D4 *'
A4* pa = &d; // error: ambiguous: C’s A or B’s A?
    ^    ~~
p44.cpp:83:1: error: ambiguous conversion from derived class 'D5' to base class 'B1':
    struct D5 -> struct I1 -> struct B1
    struct D5 -> struct I2 -> struct B1
f(); // Ambiguous conversion of this
^
p44.cpp:86:23: error: non-static member 'i' found in multiple base-class subobjects of type 'B1':
    struct D5 -> struct I1 -> struct B1
    struct D5 -> struct I2 -> struct B1
int B1::* mpB1 = &D5::i; // Unambiguous
                  ~~~~^
p44.cpp:72:5: note: member found by ambiguous name lookup
int i;
    ^
p44.cpp:87:23: error: non-static member 'i' found in multiple base-class subobjects of type 'B1':
    struct D5 -> struct I1 -> struct B1
    struct D5 -> struct I2 -> struct B1
int D5::* mpD5 = &D5::i; // Ambiguous conversion
                  ~~~~^
p44.cpp:72:5: note: member found by ambiguous name lookup
int i;
    ^
p44.cpp:91:21: error: use of undeclared identifier 'sq'
int main() { return sq(9);// OK, sq from module
                    ^
8 errors generated.

$ g++ p44.cpp -std=03 -o p44g -I. -Wall
p44.cpp: In function 'void f(D2*)':
p44.cpp:39:5: error: request for member 'a' is ambiguous
   39 | pd->a++; // error: ambiguous: two as in D
      |     ^
p44.cpp:28:5: note: candidates are: 'int A2::a'
   28 | int a;
      |     ^
p44.cpp:28:5: note:                 'int A2::a'
p44.cpp:38:5: warning: unused variable 'i' [-Wunused-variable]
   38 | int i = pd->e; // OK, only one e (enumerator)
      |     ^
p44.cpp: In member function 'void D3::glorp()':
p44.cpp:53:1: error: reference to 'y' is ambiguous
   53 | y++; // error: B::y and C’s W::y
      | ^
p44.cpp:43:25: note: candidates are: 'int W::y'
   43 | struct W { int g(); int y; };
      |                         ^
p44.cpp:46:14: note:                 'int B3::y'
   46 | int g(); int y;
      |              ^
p44.cpp:54:1: error: reference to 'g' is ambiguous
   54 | g(); // error: B::g() and C’s W::g()
      | ^
p44.cpp:43:16: note: candidates are: 'int W::g()'
   43 | struct W { int g(); int y; };
      |                ^
p44.cpp:46:5: note:                 'int B3::g()'
   46 | int g(); int y;
      |     ^
p44.cpp: In function 'void g()':
p44.cpp:65:10: error: cannot convert 'D4*' to 'A4*' in initialization
   65 | A4* pa = &d; // error: ambiguous: C’s A or B’s A?
      |          ^~
      |          |
      |          D4*
p44.cpp:64:5: warning: unused variable 'pb' [-Wunused-variable]
   64 | B4* pb = &d;
      |     ^~
p44.cpp:65:5: warning: unused variable 'pa' [-Wunused-variable]
   65 | A4* pa = &d; // error: ambiguous: C’s A or B’s A?
      |     ^~
p44.cpp:66:5: warning: unused variable 'pv' [-Wunused-variable]
   66 | V4* pv = &d; // OK, only one V subobject
      |     ^~
p44.cpp: In member function 'void D5::g()':
p44.cpp:83:2: error: 'B1' is an ambiguous base of 'D5'
   83 | f(); // Ambiguous conversion of this
      | ~^~
p44.cpp:86:23: error: reference to 'i' is ambiguous
   86 | int B1::* mpB1 = &D5::i; // Unambiguous
      |                       ^
p44.cpp:72:5: note: candidates are: 'int B1::i'
   72 | int i;
      |     ^
p44.cpp:72:5: note:                 'int B1::i'
p44.cpp:87:23: error: reference to 'i' is ambiguous
   87 | int D5::* mpD5 = &D5::i; // Ambiguous conversion
      |                       ^
p44.cpp:72:5: note: candidates are: 'int B1::i'
   72 | int i;
      |     ^
p44.cpp:72:5: note:                 'int B1::i'
p44.cpp:86:11: warning: unused variable 'mpB1' [-Wunused-variable]
   86 | int B1::* mpB1 = &D5::i; // Unambiguous
      |           ^~~~
p44.cpp:87:11: warning: unused variable 'mpD5' [-Wunused-variable]
   87 | int D5::* mpD5 = &D5::i; // Ambiguous conversion
      |           ^~~~
p44.cpp: In function 'int main()':
p44.cpp:91:21: error: 'sq' was not declared in this scope
   91 | int main() { return sq(9);// OK, sq from module
      |                     ^~
p44.cpp:93:5: error: request for member 'x' is ambiguous
   93 |   f.x = 0; // Ok, lookup finds E::x
      |     ^
p44.cpp:14:18: note: candidates are: 'float B::x'
   14 | struct B { float x; }; // S(x,B) = { { B::x }, { B } }
      |                  ^
p44.cpp:13:16: note:                 'int A::x'
   13 | struct A { int x; }; // S(x,A) = { { A::x }, { A } }
      |                ^
rm: cannot remove 'p44g': No such file or directory

$ g++ p44.cpp -std=2b -o p44g -I. -Wall
p44.cpp: In function 'void f(D2*)':
p44.cpp:39:5: error: request for member 'a' is ambiguous
   39 | pd->a++; // error: ambiguous: two as in D
      |     ^
p44.cpp:28:5: note: candidates are: 'int A2::a'
   28 | int a;
      |     ^
p44.cpp:28:5: note:                 'int A2::a'
p44.cpp:38:5: warning: unused variable 'i' [-Wunused-variable]
   38 | int i = pd->e; // OK, only one e (enumerator)
      |     ^
p44.cpp: In member function 'void D3::glorp()':
p44.cpp:53:1: error: reference to 'y' is ambiguous
   53 | y++; // error: B::y and C’s W::y
      | ^
p44.cpp:43:25: note: candidates are: 'int W::y'
   43 | struct W { int g(); int y; };
      |                         ^
p44.cpp:46:14: note:                 'int B3::y'
   46 | int g(); int y;
      |              ^
p44.cpp:54:1: error: reference to 'g' is ambiguous
   54 | g(); // error: B::g() and C’s W::g()
      | ^
p44.cpp:43:16: note: candidates are: 'int W::g()'
   43 | struct W { int g(); int y; };
      |                ^
p44.cpp:46:5: note:                 'int B3::g()'
   46 | int g(); int y;
      |     ^
p44.cpp: In function 'void g()':
p44.cpp:65:10: error: cannot convert 'D4*' to 'A4*' in initialization
   65 | A4* pa = &d; // error: ambiguous: C’s A or B’s A?
      |          ^~
      |          |
      |          D4*
p44.cpp:64:5: warning: unused variable 'pb' [-Wunused-variable]
   64 | B4* pb = &d;
      |     ^~
p44.cpp:65:5: warning: unused variable 'pa' [-Wunused-variable]
   65 | A4* pa = &d; // error: ambiguous: C’s A or B’s A?
      |     ^~
p44.cpp:66:5: warning: unused variable 'pv' [-Wunused-variable]
   66 | V4* pv = &d; // OK, only one V subobject
      |     ^~
p44.cpp: In member function 'void D5::g()':
p44.cpp:83:2: error: 'B1' is an ambiguous base of 'D5'
   83 | f(); // Ambiguous conversion of this
      | ~^~
p44.cpp:86:23: error: reference to 'i' is ambiguous
   86 | int B1::* mpB1 = &D5::i; // Unambiguous
      |                       ^
p44.cpp:72:5: note: candidates are: 'int B1::i'
   72 | int i;
      |     ^
p44.cpp:72:5: note:                 'int B1::i'
p44.cpp:87:23: error: reference to 'i' is ambiguous
   87 | int D5::* mpD5 = &D5::i; // Ambiguous conversion
      |                       ^
p44.cpp:72:5: note: candidates are: 'int B1::i'
   72 | int i;
      |     ^
p44.cpp:72:5: note:                 'int B1::i'
p44.cpp:86:11: warning: unused variable 'mpB1' [-Wunused-variable]
   86 | int B1::* mpB1 = &D5::i; // Unambiguous
      |           ^~~~
p44.cpp:87:11: warning: unused variable 'mpD5' [-Wunused-variable]
   87 | int D5::* mpD5 = &D5::i; // Ambiguous conversion
      |           ^~~~
p44.cpp: In function 'int main()':
p44.cpp:91:21: error: 'sq' was not declared in this scope
   91 | int main() { return sq(9);// OK, sq from module
      |                     ^~
p44.cpp:93:5: error: request for member 'x' is ambiguous
   93 |   f.x = 0; // Ok, lookup finds E::x
      |     ^
p44.cpp:14:18: note: candidates are: 'float B::x'
   14 | struct B { float x; }; // S(x,B) = { { B::x }, { B } }
      |                  ^
p44.cpp:13:16: note:                 'int A::x'
   13 | struct A { int x; }; // S(x,A) = { { A::x }, { A } }
      |  

検討事項(agenda)

算譜(source code)

p44.cpp

編纂・実行結果(compile and go)

bash

検討事項(agenda)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?