Skip to content

Commit 8bb356c

Browse files
authored
Update compiler-error-c2385.md
I like what you did here. Did a little word smithing on the overall topic.
1 parent 25222b7 commit 8bb356c

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

docs/error-messages/compiler-errors-1/compiler-error-c2385.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
---
22
description: "Learn more about: Compiler Error C2385"
33
title: "Compiler Error C2385"
4-
ms.date: "12/20/2023"
4+
ms.date: "1/19/2024"
55
f1_keywords: ["C2385"]
66
helpviewer_keywords: ["C2385"]
7-
ms.assetid: 6d3dd1f2-e56d-49d7-865c-6a9acdb17417
87
---
98
# Compiler Error C2385
109

11-
ambiguous access of 'member'
10+
> ambiguous access of 'member'
1211
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:
1413

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.
2018

2119
## Example
2220

@@ -39,6 +37,7 @@ struct B
3937
struct C : A, B
4038
{
4139
// Uncomment the following lines to resolve the first 2 errors
40+
// The error below for the call to c.func2() will remain
4241
// using A::func1;
4342
// using B::func1;
4443
};
@@ -49,13 +48,16 @@ int main()
4948

5049
c.func1(123); // C2385
5150
c.func1('a'); // C2385
52-
5351
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
5857
}
5958
```
6059

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:
61+
- Introduce the one you want to use into scope
62+
- Explicitly qualify the call with the base type
63+
- Cast the object before calling the function.

0 commit comments

Comments
 (0)