Permalink
Browse files

quickly submit

  • Loading branch information...
hxhb committed Mar 24, 2017
1 parent 7007cde commit 2636b49ff3aeeee542f3d00c62cc9d391884b9b9
@@ -120,6 +120,43 @@ int main() { X x(); }
改成`X x{};`就会输出X了。
### Q13
```cpp
#include <iostream>
class A {
public:
A() { std::cout << "a"; }
~A() { std::cout << "A"; }
};
class B {
public:
B() { std::cout << "b"; }
~B() { std::cout << "B"; }
};
class C {
public:
C() { std::cout << "c"; }
~C() { std::cout << "C"; }
};
A a;
int main() {
C c;
B b;
}
```
**Answer:** acbBCA
首先,因为static对象在main函数的第一条语句执行之前被初始化(实现定义):
>It is implementation-defined whether the dynamic initialization of a non-local variable with static storage duration is done before the first statement of main.
在大多数编译器下(还没碰到过不是的),全局对象a最先构造,然后cb按其定义的顺序构造,则输出就是acb.
而程序终止destory对象时则是根据定义的反序释放,则输出BCA.
### Q15
```cpp
@@ -757,6 +794,26 @@ int main()
>C++标准中规定,char是unsigned还是signed是由实现定义的,所以这个问题是implementation-define behavior.
>. It is implementation-defined whether a char object can hold negative values.
### Q153
```cpp
#include <iostream>
int main() {
char* str = "X";
std::cout << str;
}
```
>A narrow string literal has type “array of n const char”, where n is the size of the string as defined below, and has static storage duration.
在C++11中const char*转换到char*是不合法的转换。
>ISO C++11 does not allow conversion from string literal to 'char *'.
解决办法就是:
```cpp
const char* str="x";
```
### Q158
@@ -208,6 +208,13 @@
{% endif %}
</div>

<blockquote class="blockquote-center">全文完,若有不足之处望评论指正。<br/>
<div class="qr-code" onclick="return false">
<img src="https://encrypt.proxy.is26.com/qr?content={{ post.permalink }}" alt="">
<p>扫描二维码,分享此文章</p>
</div>
</blockquote>

{% if not is_index %}
<div class="postCopyright" style="clear:both;">
<span>本文标题:</span><a href="{{ url_for(post.path) }}">{{ post.title }}</a><br/>
@@ -94,4 +94,21 @@
.postCopyright .copy-path:hover {
color: #393939;
cursor: pointer;
}
}

.qr-code img{
display:block;
width:10rem;
height:10rem;
box-shadow:0 0 1px #e3e3e3
}
.qr-code img:active,.qr-code img:hover{
background:#e6e6e6;box-shadow:0 0 5px #e3e3e3
}
.qr-code p{
font-size:1rem;
line-height:1.4rem;
display:block;
margin-top:.6rem;
text-align:center;color:#999
}

0 comments on commit 2636b49

Please sign in to comment.