周末的乐趣 [英] End-of-the-week fun

查看:98
本文介绍了周末的乐趣的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TGIF !!!


我不知道人们是否会对此感兴趣,但如果是这样,我们

可能会学习一些有趣的花絮!


你知道的语言有哪些最隐晦的功能?

请排除任何不严格的部分该标准,即使是一个非常常见的扩展名。这可以是核心语言本身,也可以是

标准库。


除了模糊的特征,它存在的原因,如果已知,

听起来也很有意思!


我会抛弃一对:


1 。构造函数和析构函数名称可以用括号括起来。 ie

(~MyClass)(){...}

2.尝试将异常与catch子句匹配时,用户定义的转换。短节目

以下打印Point 2。


不幸的是,我不知道这些的原因。第1项可能没有实际令人信服的理由,但第2项确实如此。我会非常感兴趣

如果有人知道的话,请听听这种行为的原因...


#include< iostream>


使用命名空间std;


class foo_t

{

public:

foo_t(int){}

(~foo_t)(){}

};


int main( )

{

试试

{

扔45;

}

catch(foo_t)

{

cout<< 点1 <<结束;

}

catch(int)

{

cout<< 点2 <<结束;

}


返回0;

}

TGIF!!!

I don''t know if people will be interested in this or not, but if so, we
might learn a few interesting tidbits!

What are some of the most obscure features of the language you know of?
Please exclude anything that''s not strictly part of the standard, even if a
very common extension. This can be in the core language itself or in the
standard library.

In addition to the obscure feature, a reason for its existence, if known,
would also be very interesting to hear!

I''ll throw out a couple:

1. Constructor and destructor names may be surrounded by parenthesis. i.e.
(~MyClass)( ) {...}

2. When trying to match an exception to a catch clause, user-defined
conversions via a one-argument constructor are not used. The short program
below prints "Point 2".

Unfortunately, I don''t know the reasons for these. Item 1 may not have a
real compelling reason, but surely item 2 does. I''d be very interested to
hear the reason for this behavior if anybody knows...

#include <iostream>

using namespace std;

class foo_t
{
public:
foo_t(int) {}
(~foo_t)() {}
};

int main()
{
try
{
throw 45;
}
catch(foo_t)
{
cout << "Point 1" << endl;
}
catch(int)
{
cout << "Point 2" << endl;
}

return 0;
}

推荐答案

Dave写道:
TGIF !!!

我不知道人们是否会对此感兴趣,但如果是这样,我们
可能会学到一些有趣的花絮!

你知道的语言有哪些最模糊的功能?
请排除任何不严格的部分内容标准,即使是非常常见的扩展名。这可以是核心语言本身或
标准库。

除了晦涩的功能之外,它存在的原因,如果知道,
也会非常很有意思!

我会抛弃一对:

1.构造函数和析构函数名称可能被括号括起来。即
(~MyClass)(){...}

2.尝试将异常与catch子句匹配时,用户定义的
转换通过单参数不使用构造函数。下面的简短程序打印Point 2。

不幸的是,我不知道这些的原因。第1项可能没有真正令人信服的理由,


也许它更容易解析模板(甚至没有考虑过想法)

但是第2项确实如此。如果有人知道的话,我会非常有兴趣听到这种行为的原因...


这个(我认为)很明显。


考虑这个代码。


尝试

{

polyobj-> VirtFunc();
< br $>
}

catch(foo_t)

{

}

catch(int)

{

}


因为编译器不知道可能会抛出什么

它不会知道使用哪种转换功能

- 并且某些转换可能会变成

ambigous(在运行时)因为可能会有更多

比一次转换好,这只是一个坏主意。

#include< iostream>

使用命名空间std;

上课foo_t
{
公开:
foo_t(int){}
(~foo_t)(){}
};

int main()
尝试
{
抛出45;
}
catch(foo_t)
{
cout<< 点1 << endl;
}
catch(int)
{
cout<< 点2 << endl;


返回0;
}
TGIF!!!

I don''t know if people will be interested in this or not, but if so, we
might learn a few interesting tidbits!

What are some of the most obscure features of the language you know of?
Please exclude anything that''s not strictly part of the standard, even if a
very common extension. This can be in the core language itself or in the
standard library.

In addition to the obscure feature, a reason for its existence, if known,
would also be very interesting to hear!

I''ll throw out a couple:

1. Constructor and destructor names may be surrounded by parenthesis. i.e.
(~MyClass)( ) {...}

2. When trying to match an exception to a catch clause, user-defined
conversions via a one-argument constructor are not used. The short program
below prints "Point 2".

Unfortunately, I don''t know the reasons for these. Item 1 may not have a
real compelling reason,
Maybe it makes ut easier to parse templates (not even thought out idea)
but surely item 2 does. I''d be very interested to hear the reason for this behavior if anybody knows...
This one is (I think) obvious.

consider this code.

try
{
polyobj->VirtFunc();

}
catch ( foo_t )
{
}
catch ( int )
{
}

Since the compiler has no idea what might get thrown
there is no way it will know which conversion funtion
to use - and some of the conversions may become
ambigous (at run-time) since there may be more
than one conversion and that''s simply a bad idea.


#include <iostream>

using namespace std;

class foo_t
{
public:
foo_t(int) {}
(~foo_t)() {}
};

int main()
{
try
{
throw 45;
}
catch(foo_t)
{
cout << "Point 1" << endl;
}
catch(int)
{
cout << "Point 2" << endl;
}

return 0;
}






Dave在新闻中写道:vq ************ @ news.supernews.com:
Dave wrote in news:vq************@news.supernews.com:
1.构造函数和析构函数名称可以用括号括起来。
ie(~MyClass)(){...}
1. Constructor and destructor names may be surrounded by parenthesis.
i.e. (~MyClass)( ) {...}




#include< iostream>

#include< ostream> ;


#define macro(x)(std :: cout<<(x)<< std :: endl)


void(macro)(char const * x)

{

macro(x);

}

int(f(int i))

{

返回i + 1;

}


char const(* name)=" name" ;;


int main()

{

使用namespace std;


macro(f(2));

macro(" macro");

# undef macro

macro(" function");

macro(name);

}


Rob。

-
http://www.victim -prime.dsl.pipex.com/


Dave写道:
TGIF !!!
我不知道人们是否会对此感兴趣,但如果是这样,我们可能会学到一些有趣的花絮!

有哪些最隐蔽的特征是什么?您知道的语言?
请排除任何不严格属于标准的内容,即使是非常常见的扩展名。这可以是核心语言本身或
标准库。

除了晦涩的功能之外,它存在的原因,如果知道,
也会非常很有意思!

我会抛弃一对:

1.构造函数和析构函数名称可能被括号括起来。即
(~MyClass)(){...}

2.尝试将异常与catch子句匹配时,用户定义的
转换通过单参数没有使用构造函数。
TGIF!!!

I don''t know if people will be interested in this or not, but if so, we
might learn a few interesting tidbits!

What are some of the most obscure features of the language you know of?
Please exclude anything that''s not strictly part of the standard, even if a
very common extension. This can be in the core language itself or in the
standard library.

In addition to the obscure feature, a reason for its existence, if known,
would also be very interesting to hear!

I''ll throw out a couple:

1. Constructor and destructor names may be surrounded by parenthesis. i.e.
(~MyClass)( ) {...}

2. When trying to match an exception to a catch clause, user-defined
conversions via a one-argument constructor are not used.




3.通常在C和C ++中将实体声明为''int''等同于

来声明它是''signed int''。但是,在c

和C ++中都有一个上下文,其中''int''可能等同于''unsigned int''

(实现定义)。这个上下文是:位字段声明


struct S {

int i:5; //< - 有符号或无符号 - 实现已定义

};


4. C ++中有一个上下文,其中括号更改了语义

表达式的含义,即使它没有改变

运算符的绑定(由它们的优先级定义)。这个上下文是:取一个类数据成员的

地址


struct S {

int i;

};

...

& S :: i; //< - 此表达式的类型为''int(S :: *)''

&(S :: i); //< - 此表达式的类型为''int *''


5.在构造函数初始化程序列表中列出数据成员名称及其

各自的初始值设定项在不同的范围内,所以

构造函数参数名称和类数据之间没有冲突

成员名称


struct S {

int i;

S(int i):i(i)//使用参数''i''的值初始化'''' />
{}

};


-

祝你好运,

Andrey Tarasevich



3. Normally in both C and C++ declaring an entity as ''int'' is equivalent
to declaring it as ''signed int''. However, there is a context in both C
and C++ where ''int'' might be equivalent to ''unsigned int''
(implementation defined). This context is: bit field declarations

struct S {
int i:5; // <- signed or unsigned - implementation defined
};

4. There is a context in C++ where parenthesis changes the semantical
meaning of an expression even though it doesn''t alter the binding of
operators (defined by their precedence). This context is: taking the
address of a class data member

struct S {
int i;
};
...
&S::i; // <- this expression has type ''int (S::*)''
&(S::i); // <- this expression has type ''int*''

5. In constructor initializer lists data member names and their
respective initializers are looked up in different scopes, so that
there''s no conflict between constructor parameter names and class data
member names

struct S {
int i;
S(int i) : i(i) // initializes '' '' with value of parameter ''i''
{}
};

--
Best regards,
Andrey Tarasevich


这篇关于周末的乐趣的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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