使用 时decltype,是否允许在声明中使用传统的前导返回类型语法:
decltype(expr) foo();
Run Code Online (Sandbox Code Playgroud)
然后 在定义中使用C++11 尾随返回类型语法?
auto foo() -> decltype(expr) { /*...*/ }
Run Code Online (Sandbox Code Playgroud)
我认为答案是肯定的,因为 C++11 8.3.5p1(前导返回类型)和 8.3.5p2(尾随返回类型)似乎都产生相同的最终类型描述,无论返回类型出现在哪一侧,并且 7.1 .6.2p4 ( decltype) 似乎没有任何东西可以改变这一点。此外,9.3p9 中的注释显示了使用 typedef 声明成员的示例,但解释了它不能用 typedef 定义,这意味着它们不必使用完全相同的语法约定。
但是,我有一个示例,其中 Clang 和 GCC 都认为不允许这样做,尽管 MSVC 允许(godbolt 链接):
// The class must be a template for the problem to happen.
template <typename T>
struct Class {
// This has to be inside the class for the problem to happen.
int dataMember;
// All is fine if …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Turbo-C++ 同时获得鼠标和键盘输入。
我想使用两个函数。第一个函数是main可以接受键盘输入或调用该delay函数dos.h以暂时停止main().
第二个函数处理鼠标输入:
void mouse()
{
union REGS in,out;
in.x.ax=1; // Show mouse pointer
int86(0x33,&in,&out); //interrupt call
while(1)
{
//print the location whenever it changes (not required)
}
}
Run Code Online (Sandbox Code Playgroud)