virtual const char* what() const throw()
{
}
AFAIK it's a function that will return a constant pointer to a mutable char. The rest I am not sure. Could anybody help?
AFAIK它是一个函数,它将返回一个指向可变char的常量指针。剩下的我不确定。有人可以帮忙吗?
10 个解决方案
#1
23
Regarding the const throw()
part:
关于const throw()部分:
-
const
means that this function (which is a member function) will not change the observable state of the object it is called on. The compiler enforces this by not allowing you to call non-const
methods from this one, and by not allowing you to modify the values of members. -
throw()
means that you promise to the compiler that this function will never allow an exception to be emitted. This is called an exception specification, and (long story short) is useless and possibly misleading.
const表示此函数(它是一个成员函数)不会更改调用它的对象的可观察状态。编译器强制执行此操作,不允许您从此方法调用非const方法,并且不允许您修改成员的值。
throw()意味着您向编译器保证此函数永远不会允许发出异常。这被称为异常规范,(长话短说)是无用的,可能会产生误导。
#2
9
It means that what
is a virtual member function returning const char*
which can be invoked on const objects(the const in the end). throw()
means that it sort of guarantees not to throw anything.
这意味着什么是虚拟成员函数返回const char *,它可以在const对象上调用(最后是const)。 throw()意味着它保证不抛出任何东西。
check out exception specifications in C++, and note that they are deprecated in C++0x:)
查看C ++中的异常规范,并注意它们在C ++ 0x中被弃用了:)
#3
7
From left to right:
从左到右:
-
virtual
- this function may be overridden in derived classes -
const char*
- this function returns a modifiable pointer to a constant (array of) char -
what()
- this function takes no parameters -
const
- this function does not modify the (non-mutable
) members of the object on which it is called, and hence can be called onconst
instances of its class -
throw()
- this function is not expected to throw any exceptions. If it does,unexpected
will be called.
virtual - 可以在派生类中重写此函数
const char * - 此函数返回一个指向常量(数组)char的可修改指针
what() - 此函数不带参数
const - 此函数不会修改调用它的对象的(不可变的)成员,因此可以在其类的const实例上调用
throw() - 这个函数不会抛出任何异常。如果是,则会调用意外。
#4
3
virtual function returning a pointer to a non-modifiable buffer of chars, taking no arguments, does not modify any member variables of the class is belongs to (i.e. can be called on const instances), and won't throw any kind of exception.
虚函数返回指向不可修改的字符缓冲区的指针,不带参数,不修改类所属的任何成员变量(即可以在const实例上调用),并且不会抛出任何类型的异常。
#5
1
It's a virtual function that returns a const char*. The const
at the end of the method means it is not allowed to change the state of the object it is called upon. Which means it is not allowed to modify any member variables of the object. throw()
part is the exception specification that says the method doesn't throw any exception.
它是一个返回const char *的虚函数。方法结尾处的const意味着不允许更改调用它的对象的状态。这意味着不允许修改对象的任何成员变量。 throw()部分是异常规范,表示该方法不会抛出任何异常。
#6
1
the function what()
takes no parameters, returns a pointer
to a const char
(so you can't modify the what the pointer points to, but you can modify the pointer itself). It's virtual
, so its behaviour can be overridden in derived classes. It won't throw exceptions. It doesn't modify any members of the class that it belongs to.
函数what()不带参数,返回指向const char的指针(因此你不能修改指针指向的内容,但你可以修改指针本身)。它是虚拟的,因此可以在派生类中覆盖它的行为。它不会抛出异常。它不会修改它所属的类的任何成员。
#7
0
-
virtual
: This means that the function can be reimplemented in subclasses, and calls to the method via a base class pointer will end up calling the reimplementation.virtual:这意味着该函数可以在子类中重新实现,并且通过基类指针调用该方法将最终调用重新实现。
-
const char *
is not a constant pointer to a mutable char - it's the other way round.const char *不是指向可变char的常量指针 - 反之亦然。
-
const
means that this method can even be called on const instances of this class.const意味着甚至可以在此类的const实例上调用此方法。
-
throw()
means that this method will not yield any exceptions.throw()表示此方法不会产生任何异常。
#8
0
It actually returns a mutable pointer to a constant character block.
它实际上返回一个指向常量字符块的可变指针。
The rest is already explained by others.
其他人已经解释了其余部分。
#9
0
Concerning the const after the functions: there are really two meanings, what the compiler understands, and what the usual programming conventions make it mean. As far as the compiler is concerned, all it does is make the this pointer a pointer to const. The const can be cast away, or various indirections used, to modify the observable state of the object. In the end, this const means whatever the programmer wants it to mean.
关于函数之后的const:有两个含义,编译器理解的内容,以及通常的编程约定使其意味着什么。就编译器而言,它所做的就是使this指针成为指向const的指针。 const可以被抛弃,或者使用各种间接,来修改对象的可观察状态。最后,这个const意味着程序员想要的意思。
The usual convention, today, is that it means that the observable state of the object will not change. For some reasonable definition of "observable state".
今天通常的惯例是,它意味着对象的可观察状态不会改变。对于“可观察状态”的一些合理定义。
Concerning the exception specification: an empty exception specification is a no throw guarantee, and is very important when considering exception safety. The next version of the standard has deprecated exception specifications, but it does provide some other means of specifying that a function will never throw.
关于异常规范:空异常规范是无抛出保证,在考虑异常安全时非常重要。该标准的下一个版本已经弃用了异常规范,但它确实提供了一些指定函数永远不会抛出的其他方法。
#10
-1
Base class for all library exceptions.
所有库异常的基类。
This is the base class for all exceptions thrown by the standard library, and by certain language expressions. You are free to derive your own exception classes, or use a different hierarchy, or to throw non-class data (e.g., fundamental types).
这是标准库和某些语言表达式抛出的所有异常的基类。您可以*地派生自己的异常类,或使用不同的层次结构,或者抛出非类数据(例如,基本类型)。
#1
23
Regarding the const throw()
part:
关于const throw()部分:
-
const
means that this function (which is a member function) will not change the observable state of the object it is called on. The compiler enforces this by not allowing you to call non-const
methods from this one, and by not allowing you to modify the values of members. -
throw()
means that you promise to the compiler that this function will never allow an exception to be emitted. This is called an exception specification, and (long story short) is useless and possibly misleading.
const表示此函数(它是一个成员函数)不会更改调用它的对象的可观察状态。编译器强制执行此操作,不允许您从此方法调用非const方法,并且不允许您修改成员的值。
throw()意味着您向编译器保证此函数永远不会允许发出异常。这被称为异常规范,(长话短说)是无用的,可能会产生误导。
#2
9
It means that what
is a virtual member function returning const char*
which can be invoked on const objects(the const in the end). throw()
means that it sort of guarantees not to throw anything.
这意味着什么是虚拟成员函数返回const char *,它可以在const对象上调用(最后是const)。 throw()意味着它保证不抛出任何东西。
check out exception specifications in C++, and note that they are deprecated in C++0x:)
查看C ++中的异常规范,并注意它们在C ++ 0x中被弃用了:)
#3
7
From left to right:
从左到右:
-
virtual
- this function may be overridden in derived classes -
const char*
- this function returns a modifiable pointer to a constant (array of) char -
what()
- this function takes no parameters -
const
- this function does not modify the (non-mutable
) members of the object on which it is called, and hence can be called onconst
instances of its class -
throw()
- this function is not expected to throw any exceptions. If it does,unexpected
will be called.
virtual - 可以在派生类中重写此函数
const char * - 此函数返回一个指向常量(数组)char的可修改指针
what() - 此函数不带参数
const - 此函数不会修改调用它的对象的(不可变的)成员,因此可以在其类的const实例上调用
throw() - 这个函数不会抛出任何异常。如果是,则会调用意外。
#4
3
virtual function returning a pointer to a non-modifiable buffer of chars, taking no arguments, does not modify any member variables of the class is belongs to (i.e. can be called on const instances), and won't throw any kind of exception.
虚函数返回指向不可修改的字符缓冲区的指针,不带参数,不修改类所属的任何成员变量(即可以在const实例上调用),并且不会抛出任何类型的异常。
#5
1
It's a virtual function that returns a const char*. The const
at the end of the method means it is not allowed to change the state of the object it is called upon. Which means it is not allowed to modify any member variables of the object. throw()
part is the exception specification that says the method doesn't throw any exception.
它是一个返回const char *的虚函数。方法结尾处的const意味着不允许更改调用它的对象的状态。这意味着不允许修改对象的任何成员变量。 throw()部分是异常规范,表示该方法不会抛出任何异常。
#6
1
the function what()
takes no parameters, returns a pointer
to a const char
(so you can't modify the what the pointer points to, but you can modify the pointer itself). It's virtual
, so its behaviour can be overridden in derived classes. It won't throw exceptions. It doesn't modify any members of the class that it belongs to.
函数what()不带参数,返回指向const char的指针(因此你不能修改指针指向的内容,但你可以修改指针本身)。它是虚拟的,因此可以在派生类中覆盖它的行为。它不会抛出异常。它不会修改它所属的类的任何成员。
#7
0
-
virtual
: This means that the function can be reimplemented in subclasses, and calls to the method via a base class pointer will end up calling the reimplementation.virtual:这意味着该函数可以在子类中重新实现,并且通过基类指针调用该方法将最终调用重新实现。
-
const char *
is not a constant pointer to a mutable char - it's the other way round.const char *不是指向可变char的常量指针 - 反之亦然。
-
const
means that this method can even be called on const instances of this class.const意味着甚至可以在此类的const实例上调用此方法。
-
throw()
means that this method will not yield any exceptions.throw()表示此方法不会产生任何异常。
#8
0
It actually returns a mutable pointer to a constant character block.
它实际上返回一个指向常量字符块的可变指针。
The rest is already explained by others.
其他人已经解释了其余部分。
#9
0
Concerning the const after the functions: there are really two meanings, what the compiler understands, and what the usual programming conventions make it mean. As far as the compiler is concerned, all it does is make the this pointer a pointer to const. The const can be cast away, or various indirections used, to modify the observable state of the object. In the end, this const means whatever the programmer wants it to mean.
关于函数之后的const:有两个含义,编译器理解的内容,以及通常的编程约定使其意味着什么。就编译器而言,它所做的就是使this指针成为指向const的指针。 const可以被抛弃,或者使用各种间接,来修改对象的可观察状态。最后,这个const意味着程序员想要的意思。
The usual convention, today, is that it means that the observable state of the object will not change. For some reasonable definition of "observable state".
今天通常的惯例是,它意味着对象的可观察状态不会改变。对于“可观察状态”的一些合理定义。
Concerning the exception specification: an empty exception specification is a no throw guarantee, and is very important when considering exception safety. The next version of the standard has deprecated exception specifications, but it does provide some other means of specifying that a function will never throw.
关于异常规范:空异常规范是无抛出保证,在考虑异常安全时非常重要。该标准的下一个版本已经弃用了异常规范,但它确实提供了一些指定函数永远不会抛出的其他方法。
#10
-1
Base class for all library exceptions.
所有库异常的基类。
This is the base class for all exceptions thrown by the standard library, and by certain language expressions. You are free to derive your own exception classes, or use a different hierarchy, or to throw non-class data (e.g., fundamental types).
这是标准库和某些语言表达式抛出的所有异常的基类。您可以*地派生自己的异常类,或使用不同的层次结构,或者抛出非类数据(例如,基本类型)。