可访问性不一致:基类的可访问性低于类 [英] Inconsistent accessibility: base class is less accessible than class

查看:682
本文介绍了可访问性不一致:基类的可访问性低于类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在DLL中有一个抽象基类,并且该类具有子类。我希望孩子是公开的,但希望基地是私有的,以便不能在dll之外访问它。

So I have an abstract base class in a DLL and child classes of that class. I want the childs to be public, but the base to be private so that it cannot be accessed outside of the dll.

我该怎么做?

推荐答案

您不可以,也不能。

如果要将类公开为 public ,基本类型必须必须为 public 。另一种选择是拥有公共接口,并且仅通过接口公开类型(大概是使用工厂方法)

If you want to expose the class as public, the base-type must be public. One other option is to have a public interface, and only expose the type via the interface (presumably with a factory method somewhere for creating instances).

最后一个选择是封装基类,而不是继承它。

One final option is to encapsulate the base-class rather than inherit it.

这篇关于可访问性不一致:基类的可访问性低于类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆