我偶然发现了我认为是stl算法推进中的一个错误.
当我从容器的末端推进迭代器时,我得到的结果不一致.有时候我得到container.end(),有时我会得到最后一个元素.我用以下代码说明了这一点:
#include <algorithm>
#include <cstdio>
#include <set>
using namespace std;
typedef set<int> tMap;
int main(int argc, char** argv)
{
tMap::iterator i;
tMap the_map;
for (int i=0; i<10; i++)
the_map.insert(i);
#if EXPERIMENT==1
i = the_map.begin();
#elif EXPERIMENT==2
i = the_map.find(4);
#elif EXPERIMENT==3
i = the_map.find(5);
#elif EXPERIMENT==4
i = the_map.find(6);
#elif EXPERIMENT==5
i = the_map.find(9);
#elif EXPERIMENT==6
i = the_map.find(2000);
#else
i = the_map.end();
#endif
advance(i, 100);
if (i == the_map.end())
printf("the end\n");
else
printf("wuh? %d\n", *i);
return …Run Code Online (Sandbox Code Playgroud) 我有一个过程,它逐步输出消息(即处理项目1 ......项目2中的错误等).
我希望在此过程中将其输出给用户,而不是在最后.
我很确定我需要使用线程来做这件事,但找不到一个像样的例子.
在下面的代码中,MousePressImage是类的依赖属性ButtonControl.以下绑定不起作用.感谢您帮助解决此问题.
Value="{Binding RelativeSource={x:Static RelativeSource.Self},
Path=MousePressImage}"/>
<Style TargetType="{x:Type local:ButtonControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:ButtonControl}">
<Border>
<Image x:Name="img"
Source="pack://application:,,,/Recipe_06_13;component/Resources/normal.bmp"
/>
</Border>
<!--<Border x:Name="border">
<Border.Background>
<ImageBrush x:Name="img"
ImageSource="/Recipe_06_13;component/Resources/fatal.png"/>
</Border.Background>
</Border>-->
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="img"
Property="Source"
Value="{Binding RelativeSource={x:Static RelativeSource.Self},
Path=MousePressImage}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
我创造了ButtonControl这样的.
<local:ButtonControl Height="48" Width="160"
MouseOverImage="pack://application:,,,/Recipe_06_13;component/Resources/Over.bmp"
MousePressImage="pack://application:,,,/Recipe_06_13;component/Resources/Press.bmp"
DisableImage=" ">
</local:ButtonControl>
Run Code Online (Sandbox Code Playgroud) 有没有人知道如何通过jquery中的事件自动跳转到可滚动区域的底部(如果没有简单的jquery解决方案,甚至是javascript)?
问候
我想运行1000次迭代的程序,所以在main中设置一个1000的计数器.我需要在每次迭代后重新初始化各种变量,并且由于类构造函数已经写出了所有初始化 - 我决定在每次迭代后调用它,每次迭代的结果存储在main中的变量中.
然而,当我打电话给构造函数时,它没有任何影响......我花了一段时间才弄明白 - 但它没有重新初始化任何东西!
我创建了一个与构造函数完全相同的函数 - 因此对象将拥有自己的版本.当我打电话给它时,它按照我的预期重新初始化了一切.
int main()
{
Class MyClass()
int counter = 0;
while ( counter < 1000 )
{ stuff happens }
Class(); // This is how I tried to call the constructor initially.
// After doing some reading here, I tried:
// Class::Class();
// - but that didn't work either
/* Later I used...
MyClass.function_like_my_constructor; // this worked perfectly
*/
}
Run Code Online (Sandbox Code Playgroud)
......有人试图解释我为什么做错了,或者没有用,或者是愚蠢的或者你有什么?我的意思是 - 在心理上,我只是想 - 废话,我可以调用这个构造函数并重新初始化所有这些东西.构造函数(理想情况下)是否仅在创建对象时调用?
我喜欢这个问题中提到的算法:"这是如何工作的?奇怪的河内解决方案塔" 这是如何工作的?河内解决方案奇怪的塔
有没有什么办法可以扩展河内塔楼的非递归解决方案来使用X盘和Y塔,塔楼代表堆栈?
如果我错了,请纠正我,但Adobe AIR目前只允许应用程序具有256x256的最大大小图标.
更新: AIR 2仍然不支持导入512x512大小的图标.
更新2: AIR 2.7仍然不支持导入大于128 x 128的图标大小.荒唐可笑!

短篇故事:
我无法使用gcc -c选项使预编译的头文件正常工作.
很长的故事:
伙计们,我在Linux上使用gcc-4.4.1,在一个非常大的项目中尝试预编译头之前,我决定在简单程序上测试它们.他们"有点工作",但我对结果不满意,我确信我的设置有问题.
首先,我编写了一个简单的程序(main.cpp)来测试它们是否可以工作:
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/type_traits.hpp>
int main()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然后我创建了预编译头文件pre.h(在同一目录中),如下所示:
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/type_traits.hpp>
Run Code Online (Sandbox Code Playgroud)
...并编译它:
$ g++ -I. pre.h
Run Code Online (Sandbox Code Playgroud)
(pre.h.gch创建)
之后,我使用和不使用预编译头来测量编译时间:
与pch
$ time g++ -I. -include pre.h main.cpp
real 0m0.128s
user 0m0.088s
sys 0m0.048s
Run Code Online (Sandbox Code Playgroud)
没有pch
$ time g++ -I. main.cpp
real 0m0.838s
user 0m0.784s
sys 0m0.056s
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好!快了近7倍,令人印象深刻!现在让我们尝试一些更现实的东西.我的所有资源都是使用-c选项构建的,出于某种原因我无法使用pch.您可以通过以下步骤重现这一点......
我创建了测试模块foo.cpp,如下所示:
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/type_traits.hpp>
int whatever()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
以下是我尝试使用和不使用pch构建模块foo.cpp的时间:
与pch
$ time g++ -I. …Run Code Online (Sandbox Code Playgroud) 我需要传输一个不同长度的数组,其中每个元素是两个整数的元组.举个例子:
path = [(1,1),(1,2)]
path = [(1,1),(1,2),(2,2)]
Run Code Online (Sandbox Code Playgroud)
我试图使用pack和unpack,但是,由于数组的长度不同,我不知道如何创建一个格式,使得两者都知道格式.我试图将它变成带分隔符的单个字符串,例如:
msg = 1&1~1&2~
sendMsg = pack("s",msg) or sendMsg = pack("s",str(msg))
Run Code Online (Sandbox Code Playgroud)
在接收方:
path = unpack("s",msg)
Run Code Online (Sandbox Code Playgroud)
但在这种情况下只打印1.我也试图发送4个整数,只要我不包含代表路径的额外字符串,它就会发送和接收.
sendMsg = pack("hhhh",p.direction [0],p.direction [1],p.id,p.health)
在接收方:
x,y,id,health = unpack("hhhh",msg)
Run Code Online (Sandbox Code Playgroud)
第一个是插图,因为我试图发送格式"hhhhs",但无论哪种方式路径都没有正确通过.
谢谢您的帮助.我还将研究发送一个二维数组的整数,但我似乎无法弄清楚如何在网络中发送这些更"复杂"的结构.
谢谢您的帮助.
我正在编写一个允许参数"设置"的插件.但我预测用户不会总是想要设置功能的每个方面.
function This_Function(a,b,c,d);
Run Code Online (Sandbox Code Playgroud)
比如,也许他们会只希望建立a和c,但不b和d(他们就会宁愿让那些为默认值).如何编写函数(或相关参数),以便用户可以自定义他们希望传递的函数?我有一种感觉它涉及解析输入,但我已经看到许多具有此功能的其他功能.
在此先感谢您的帮助.
c++ ×3
jquery ×2
air ×1
algorithm ×1
arrays ×1
asp.net ×1
c# ×1
constructor ×1
flash ×1
function ×1
gcc ×1
icons ×1
iteration ×1
javascript ×1
networking ×1
pack ×1
parameters ×1
progress-bar ×1
python ×1
scroll ×1
stack ×1
stl ×1
unpack ×1
wpf ×1