为什么第一个返回引用?
int x = 1;
int y = 2;
(x > y ? x : y) = 100;
Run Code Online (Sandbox Code Playgroud)
而第二个不?
int x = 1;
long y = 2;
(x > y ? x : y) = 100;
Run Code Online (Sandbox Code Playgroud)
实际上,第二个根本没有编译 - "没有左边的赋值".
这个难题在NDC 2010上发布.有视频链接,但它们都被打破了.我不明白这个程序的行为; 为什么会挂?
class Woot
{
private static float PI;
private static bool initialized = doInitialize();
private static bool doInitialize()
{
if (!initialized)
{
var thread = new Thread(() => { PI = 3.14f; });
thread.Start();
thread.Join(); // here
}
return true;
}
public static void Main(string[] args)
{
Console.WriteLine(PI);
}
}
Run Code Online (Sandbox Code Playgroud)
这个程序的输出是什么?是吗:
- 3.14
- 0
- 引发异常
- 以上都不是
在第91页的"C++标准库 "一书中,我读过以下内容shared_from_this()
:
问题是,
shared_ptr
卖场本身的私有成员Person
的基类enable_shared_from_this<>
,在最后的人的建设.
该书的相关代码片段是:
class Person : public std::enable_shared_from_this<Person> {
...
};
Run Code Online (Sandbox Code Playgroud)
我不明白这里有两件事:
shared_ptr
存储自己?Person
?我认为构造Person
最终是由我编写的构造函数的最后一个语句.我知道还有weak_ptr
尚未初始化的内容.
编辑:感谢Angew!shared_from_this
将工作后,才第一次shared_ptr
来Person
创建.这shared_ptr
将检查Person
类是否继承enable_shared_from_this
,如果是,则初始化其内部weak_ptr
.
由于文件名中的空格,下一个代码不起作用,如何修复?
IFS = '\n'
for name in `ls `
do
number=`echo "$name" | grep -o "[0-9]\{1,2\}"`
if [[ ! -z "$number" ]]; then
mv "$name" "./$number"
fi
done
Run Code Online (Sandbox Code Playgroud) 有没有办法告诉visual studio为bin和obj目录使用不同的位置.例如,如果我的项目位于c:\ my\myprojects.csproj中,我如何将obj和bin目录放在d:\ otherdirectory\bin和d:\ otherdirectory\_ obj中.Visual Studio项目选项仅提供重定向bin目录,而不是obj目录.
此外,红利问题:我可以使用环境变量,而不是完整或相对路径?
这可能吗?
谢谢
我认为预处理器逐个处理文件,我无法弄清楚如何使用包含文件,所以我认为这是不可能的,但听到别人的想法会很棒.
我有a.cpp
:
#define A 1
Run Code Online (Sandbox Code Playgroud)
我想从中使用它2.cpp
.
编辑:我不能修改第一个文件.所以现在我只是复制了定义.但问题仍然存在.
我试过这段代码:
print_next(Current) ->
case mnesia:dirty_next(muppet, Current) of
'$end_of_table' ->
io:format("~n", []),
ok;
Next ->
[Muppet] = mnesia:dirty_read({muppet, Next}),
io:format("~p~n", [Muppet]),
print_next(Next),
ok
end.
print() ->
case mnesia:dirty_first(muppet) of
'$end_of_table' ->
ok;
First ->
[Muppet] = mnesia:dirty_read({muppet, First}),
io:format("~p~n", [Muppet]),
print_next(First),
ok
end.
Run Code Online (Sandbox Code Playgroud)
但它太长了.我也可以使用dirty_all_keys
然后遍历键列表,但我想知道是否有更好的方法来打印Mnesia表内容.
我可以使用g ++ -c test.cpp -std = c ++ 0x创建.o文件,但无法链接它,得到下一个错误:
test.cpp:(.text+0xe5): undefined reference to `std::regex_iterator<char const*, char, std::regex_traits<char> >::regex_iterator(char const*, char const*, std::basic_regex<char, std::regex_traits<char> > const&, std::bitset<11u>)'
test.cpp:(.text+0xf1): undefined reference to `std::regex_iterator<char const*, char, std::regex_traits<char> >::regex_iterator()'
Run Code Online (Sandbox Code Playgroud)
码:
#include <regex>
#include <iostream>
#include <string.h>
typedef std::regex_iterator<const char *> Myiter;
int main()
{
const char *pat = "axayaz";
Myiter::regex_type rx("a");
Myiter next(pat, pat + strlen(pat), rx);
Myiter end;
return (0);
}
Run Code Online (Sandbox Code Playgroud) 我需要获得浮动NaN和无穷大,但我不能使用这样的结构
0. / 0.
1. / 0.
Run Code Online (Sandbox Code Playgroud)
因为它会导致编译时间
错误C2124:除以或除以零
编辑,很高兴有答案我可以得到这个数字(每个+1),但有可能除以零?
我正在阅读关于DirectXMath的文档,并偶然发现了下一篇文章:
作为通过重载new/delete直接在C++类中强制执行对齐的替代方法,您可以使用pImpl惯用法.如果确保您的Impl类在内部通过__aligned_malloc对齐,则可以在内部实现中自由使用对齐的类型.当'public'类是Windows运行时ref类或打算与std :: shared_ptr <>一起使用时,这是一个很好的选择,否则会破坏仔细对齐.
我不明白shared_ptr如何在对齐策略中做任何改变,它只有一个指针,它不会分配一个对象.