我用C++编写一个简单的代码,然后在linux ubuntu 11.04上用g ++编译它,我没有得到任何错误,但是当我运行可执行文件时,我得到这个错误"分段错误".
我知道我的代码没有问题,并且这个错误与编译器有关.
有人能帮助我吗?
我的代码是:
#include <math.h>
int main()
{
double a[200][200][200],b[200][200][200],c[200][200][200];
int i,j,k;
double const pi=3.14;
for(k=0;k<200;k++)
{
for(j=0;j<200;j++)
{
for(i=0;i<200;i++)
{
a[i][j][k]=sin(1.5*pi*i)*cos(3.5*pi*j)*k;
b[i][j][k]=cos(1.5*pi*i)*cos(2.5*pi*k)*j;
c[i][j][k]=a[i][j][k]-b[i][j][k];
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将名为VoiceWalker的简单音频实用程序移植到Javascript.VoiceWalker是一个帮助人们录制音频的工具,它的工作原理如下:
因此,它的想法是它播放了一些,重复它,向前滑动,再次播放,重复播放,向前滑动等等.
我拼凑了一个函数来播放声音片段,它看起来像这样:
function clip(audio, start, stop){
audio.currentTime = start;
audio.play();
int = setInterval(function() {
if (audio.currentTime > stop) {
audio.pause();
clearInterval(int);
}
}, 10);
}
Run Code Online (Sandbox Code Playgroud)
提出一个与上述模式匹配的开始/停止时间列表是一个简单的命题,但是有一个问题:我如何排队我的clip()呼叫,以便只有在另一个停止后才能运行?
我试图通过提供内存中缓存来减少数据库访问量。我了解可以通过使用会话和cookie来获得缓存,但是这仅适用于每个客户端。如果在每个会话中都进行一次相同的查询,则缓存将无用。但是我只想访问一次数据库并对其进行缓存。
有没有一种方法可以在服务器端脚本可以访问的内存中创建缓存?我不想将缓存数据存储在文件中。
我正在制作一个使用键盘上很多键的HTML游戏.我设置了事件处理程序$(document).keypress,但是当我按下Firefox中的'或/键时,会出现"快速查找",中断游戏并将焦点从文档中移开.
我怎么能禁用它?我在Chrome中没有问题.
我正在写一个有各种消息输出的类.我想使这个类具有通用性和平台独立性,所以我想将一个basic_ostream引用传递给它,它可以将所有消息转储到流中.通过这样做,如果在控制台程序中使用该类,我可以将std :: cout传递给它并显示在控制台窗口中.
或者我可以将派生的ostream传递给它并将消息重定向到某些UI组件,例如ListBox?唯一的问题是数据插入器operator <<不是虚函数.如果我将派生类引用传递给它,则只会调用basic_ostream <<运算符.
这有什么解决方法吗?
算法的 python 实现是否可以与标准 C 库一起透明地工作?如果我有两个程序,一个是 Python,另一个是 C,尝试获取单个文件的锁会起作用吗?
快速链接:
我对装配很新,现在我想了解它的cmp工作原理.以下是wiki中的内容:
cmp arg2, arg1
Run Code Online (Sandbox Code Playgroud)
在arg1和arg2之间执行比较操作.通过从arg1中减去arg2的(带符号)来执行比较,其结果可以称为Temp.然后丢弃温度.
什么意思"然后丢弃温度"?它存放在哪里?如何访问此比较结果?有人可以解释一下吗?
我正在尝试将现有文件添加为Visual Studio 2010中的网站项目的链接.这样它们将被添加为参考而不是文件的新副本.VS2010帮助说在Add下拉框中的打开文件对话框中应该有一个"Add as Link"选项.但是,我只在下拉列表中看到"添加"选项,这会添加文件的新副本而不是链接.
我必须在这里遗漏一些明显的东西,但不确定是什么.非常感谢您的帮助.
问题是来自另一个访问向量并删除迭代器的类的愚蠢错误.与下面的代码无关.抱歉浪费你的时间.
我必须错过一些基本的东西.我有一个函数创建一个对象,操纵它的数据然后将其推送到一个向量中.函数退出的那一刻,程序崩溃了一个SIGSEV,我就盯着(Kdevelop gcc 4.5 gdb):
/**
* The dtor only erases the elements, and note that if the
* elements themselves are pointers, the pointed-to memory is
* not touched in any way. Managing the pointer is the user's
* responsibility.
*/
~vector()
{ std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
_M_get_Tp_allocator()); }
Run Code Online (Sandbox Code Playgroud)
我不存储指针,我正在尝试存储实例化的对象.
void Init::initIndividual(int ID, int gen)
{
Individual temp_person = Individual(ID,gen);
int inst_size = getRandom<int>(1,max_inst_size);
for (int k=0;k<inst_size;k++)
{
retry:
// (1) randomly choose a body part
int body_num = getRandom<int>(1,20);
body_part …Run Code Online (Sandbox Code Playgroud) 我有一个我想绑定到lua的类.减少的代码可能是:
class CSprite2D{
void setPosition(glm::ivec2 val) { m_position = val; }
void setPosition(int posX, int posY) { m_position.x = posX; m_position.y = posY; }
static void exposeAPI(lua_State* L,const unsigned char* data)
{
assert(L);
luabind::module(L)[
luabind::class_<CSprite2D>("CSprite2D")
.def("setPosition",(void(*)(int,int))&CSprite2D::setPosition)
];
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译时,编译器抛出并出错:
Error 1 error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'void (__cdecl *)(int,int)' c:\directo\gameprojects2008\zeleste2d\src\graphics\gpx\sprite2d.cpp 74
Error 2 error C2780: 'luabind::class_<T> &luabind::class_<T>::def(luabind::detail::operator_<Derived>)' : expects 1 arguments - 2 provided c:\directo\gameprojects2008\zeleste2d\src\graphics\gpx\sprite2d.cpp 74
Error 3 error C2784: 'luabind::class_<T> &luabind::class_<T>::def(luabind::detail::operator_<Derived>,const Policies &)' : …Run Code Online (Sandbox Code Playgroud)