本文介绍了使用声明问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我不能在使用声明中使用类析构函数:


使用MyClass :: ~MyClass;





-

Christopher Benson-Manica |我*应该*知道我在说什么 - 如果我

ataru(at)cyberspace.org |不,我需要知道。火焰欢迎。

解决方案




有趣的问题!它似乎被语法所允许;然而,由于某些其他原因,它可能是非法的。


VC7.1是我尝试过的唯一接受它的编译器。


Jonathan





因为析构函数(如构造函数)没有名称,并使用

声明需要一个名字。


-


Pete Becker

Dinkumware,Ltd。()





============= ===================================== ============= =====

ISO / IEC 14882:1998(E)


7.3.3使用声明


4 A使用* -declaration作为成员* -declaration将

引用给所定义类的基类成员,

指的是匿名联盟的成员,该联盟是所定义类的

基类的成员,或者应引用

枚举器作为枚举类型的成员一个基础

类定义的类。 [例如:


class C {

int g();

};


类D2:公共B {

使用B :: f; // OK:B是使用B :: e的D2

的基础; //好的:e是使用B :: x的基数B的枚举器

; // OK:x是使用C :: g的基数B

的联合成员; //错误:C不是D2的基础

};


- 末端示例] [注意:因为构造函数和析构函数不是

有名称,使用* -declaration不能引用构造函数<< =====

或基类的析构函数。由于名称查找找不到转换函数的成员

模板的特化,

当使用* -declaration指定
$ b $时不考虑它们b转换函数(14.5.2)。 ]如果赋值运算符从基类带入了派生类范围,则派生类的签名为

a copy * -assignment运算符(12.8),使用* -

声明本身不会抑制派生类副本* -assignment运算符的隐式声明

;来自基类的副本* -assignment

运算符被派生类的

隐式* -declared copy * -assignment运算符隐藏或覆盖,

如下所述。

================================== ================ ==================

-Mike


Why can''t I use a class destructor in a using declaration:

using MyClass::~MyClass;

?

--
Christopher Benson-Manica | I *should* know what I''m talking about - if I
ataru(at)cyberspace.org | don''t, I need to know. Flames welcome.

解决方案



Interesting question! It seems to be allowed by the grammar; it may be
illegal for some other reason, however.

VC7.1 is the only compiler I''ve tried which accepts it.

Jonathan




Because destructors, like constructors, do not have names, and a using
declaration requires a name.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)




================================================== ==================
ISO/IEC 14882:1998(E)

7.3.3 The using declaration

4 A using*-declaration used as a member*-declaration shall refer
to a member of a base class of the class being defined, shall
refer to a member of an anonymous union that is a member of a
base class of the class being defined, or shall refer to an
enumerator for an enumeration type that is a member of a base
class of the class being defined. [Example:

class C {
int g();
};

class D2 : public B {
using B::f; // OK: B is a base of D2
using B::e; // OK: e is an enumerator of base B
using B::x; // OK: x is a union member of base B
using C::g; // error: C isn?t a base of D2
};

--end example] [Note: since constructors and destructors do not
have names, a using*-declaration cannot refer to a constructor <<=====
or a destructor for a base class. Since specializations of member
templates for conversion functions are not found by name lookup,
they are not considered when a using*-declaration specifies a
conversion function (14.5.2). ] If an assignment operator brought
from a base class into a derived class scope has the signature of
a copy*-assignment operator for the derived class (12.8), the using*-
declaration does not by itself suppress the implicit declaration
of the derived class copy*-assignment operator; the copy*-assignment
operator from the base class is hidden or overridden by the
implicitly*-declared copy*-assignment operator of the derived class,
as described below.
================================================== ==================
-Mike


这篇关于使用声明问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 15:21