visual studio 贫瘠荒地发生的怪事

Strange happenings in the barren wastes of visual studio

所以当发生这种情况时,我正愉快地定义一个新的 class:

class Thing : public OtherThing
{
public:
    Thing : public OtherThing();//here
};

我真的不知道为什么 visual assist/studio 这样做而且我以前从未见过它所以我的问题是它是什么意思?

为了清楚起见,我通常会这样定义相同的 class:

class Thing : public OtherThing
{
public:
    Thing();
};

public 关键字在 2 个上下文中定义:

  1. 将对基 class 成员的访问延迟到他们声明的访问级别:

When a class uses public member access specifier to derive from a base, all public members of the base class are accessible as public members of the derived class and all protected members of the base class are accessible as protected members of the derived class (private members of the base are never accessible unless friended)[source]

  1. 为在此说明符之后声明的所有成员指定访问级别

Public members form a part of the public interface of the class (other parts of the public interface are the non-member functions found by Argument-Dependent Lookup).
A public member of a class is accessible everywhere.[source]

由于您演示的代码未声明继承 (1) 或指定成员访问权限 (2),因此使用无效关键字,不应编译。

我看到你的说法 , but indeed this cannot compile in gcc: http://ideone.com/Z33viJ or in Visual Studio 2015, which you can validate by going here: http://webcompiler.cloudapp.net/ 我能想到的唯一合理的解释是出现故障,您的编辑器显示给您的代码不是写入文件的代码,因此不是正在编译的内容。如果是这种情况,也许重新启动 Visual Studio 可以解决问题。