You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/error-messages/compiler-errors-1/compiler-error-c2385.md
+17-15Lines changed: 17 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,20 @@
1
1
---
2
2
description: "Learn more about: Compiler Error C2385"
3
3
title: "Compiler Error C2385"
4
-
ms.date: "12/20/2023"
4
+
ms.date: "1/19/2024"
5
5
f1_keywords: ["C2385"]
6
6
helpviewer_keywords: ["C2385"]
7
-
ms.assetid: 6d3dd1f2-e56d-49d7-865c-6a9acdb17417
8
7
---
9
8
# Compiler Error C2385
10
9
11
-
ambiguous access of 'member'
10
+
> ambiguous access of 'member'
12
11
13
-
The member can be inherited from more than one base type causing an unqualified access to be ambiguous. To resolve this error:
12
+
A member is inherited from more than one base type, making unqualified access to that member ambiguous. To resolve this error:
14
13
15
-
- Make the member unambiguous by explicitly qualifying it, or providing a cast.
16
-
17
-
- Rename the ambiguous members in the base classes.
18
-
19
-
- Bring the desired member into scope.
14
+
- Explicitly qualify access to the member.
15
+
- Cast the object to the base class containing the member before accessing the member.
16
+
- Rename the ambiguous member in the base class.
17
+
- Bring the member into scope.
20
18
21
19
## Example
22
20
@@ -39,6 +37,7 @@ struct B
39
37
structC : A, B
40
38
{
41
39
// Uncomment the following lines to resolve the first 2 errors
40
+
// The error below for the call to c.func2() will remain
42
41
// using A::func1;
43
42
// using B::func1;
44
43
};
@@ -49,13 +48,16 @@ int main()
49
48
50
49
c.func1(123); // C2385
51
50
c.func1('a'); // C2385
52
-
53
51
c.func2(); // C2385
54
-
c.A::func2(); // OK
55
-
c.B::func2(); // OK
56
-
static_cast<A>(c).func2(); // OK
57
-
static_cast<B>(c).func2(); // OK
52
+
53
+
c.A::func2(); // OK because explicitly qualified
54
+
c.B::func2(); // OK because explicitly qualified
55
+
static_cast<A>(c).func2(); // OK because of the cast
56
+
static_cast<B>(c).func2(); // OK because of the cast
58
57
}
59
58
```
60
59
61
-
Ambiguous calls to `func1` can be resolved by bringing both overloads into scope. However, doing the same for `func2` does not fix the error, since both `A::func2` and `B::func2` take no arguments and are still ambiguous. If only one is desired, introducing just one into scope does fix the issue. Alternatively, the call can be explicitly qualified with the base type, or the object can be casted before the function is called.
60
+
You can resolve the ambiguous calls to `func1` by bringing both overloads into scope. However, this doesn't work for `func2` because `A::func2` and `B::func2` don't take arguments, so calling them can't be differentiated by their parameters. You can resolve the issue by:
0 commit comments