我写了一个列表作为变量的类.我有一个添加到该列表的函数和一个输出该列表的函数.
class MyClass:
myList = []
def addToList(self, myNumber):
self.myList.append(myNumber)
def outputList(self):
for someNumber in self.myList:
print someNumber
Run Code Online (Sandbox Code Playgroud)
现在出于一些奇怪的原因,如果我声明该类的两个单独的对象:
ver1 = MyClass()
ver2 = MyClass()
Run Code Online (Sandbox Code Playgroud)
然后在ver1上调用addToList:
ver1.addToList(3)
Run Code Online (Sandbox Code Playgroud)
然后输出ver2的列表:
ver2.outputList()
Run Code Online (Sandbox Code Playgroud)
我得到3作为版本2列表的输出!怎么了?
以下代码给出了一个分段错误:
bool primeNums[100000000]; // index corresponds to number, t = prime, f = not prime
for (int i = 0; i < 100000000; ++i)
{
primeNums[i] = false;
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我将数组声明更改为动态:
bool *primeNums = new bool[100000000];
Run Code Online (Sandbox Code Playgroud)
我没有得到一个段错误.我有一个大致的想法,为什么会这样:在第一个例子中,内存被放在堆栈上,而在动态情况下,它被放在堆上.
你能更详细地解释一下吗?
我有一个相对较大的类,我正在使用它,到目前为止一切正常(注意:我实际上没有编写类,我只是添加了一些功能).但是,在头文件中再声明一个字符串后,现在一切都崩溃了(我得到了内存访问错误).如果我删除该字符串并重建,一切正常.
我实际上并没有使用该字符串做任何事情....只是声明它的行为导致了一些奇怪的内存错误.
我无法详细解释这个问题,因为尝试解释每个功能都是浪费.我应该在这里寻找什么样的东西才能找到问题?什么可能导致这种奇怪的行为?
错误本身是:
Unhandled exception at 0x65fd17fd (msvcp80d.dll) in myFile.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd.
基本上.h文件中的所有更改都是:
StringType string1;
Run Code Online (Sandbox Code Playgroud)
转换成:
StringType string1;
StringType string2;
Run Code Online (Sandbox Code Playgroud)
StringType是basic_string的扩展
c++ visual-studio-2005 unhandled-exception undefined-behavior write-error
我的目标是访问作为myFunction内部参数传入的类.
这是我正在尝试做的事情:
void myFunction(string myString)
{
callFunctionOn(OuterType::InnerType::myString);
}
Run Code Online (Sandbox Code Playgroud)
我试图在一个类型的东西上调用一些函数.例如,我在其他文件中的代码可能如下所示:
namespace OuterType {
namespace InnerType {
//stuff here
}
}
Run Code Online (Sandbox Code Playgroud)
但是,以这种方式使用myString不起作用.如果myString持有值"class1",那么我希望将callFunctionOn部分解释为
callFunctionOn(OuterType::InnerType::class1);
Run Code Online (Sandbox Code Playgroud)
我觉得这很简单,但我整天都在编程,我的思绪变得疲惫......
求助:看起来就像这样,我需要一种带反射的语言.为了解决这个问题,我对问题采取了不同的方法,并将指针传递给了类.
我是Java的新手,我需要一些帮助来完成这个程序.这是大型项目的一小部分,我必须使用多线程.
这是我想要算法做的事情:
while (there is still input left, store chunk of input in <chunk>)
{
if there is not a free thread in my array then
wait until a thread finishes
else there is a free thread then
apply the free thread to <chunk> (which will do something to chunk and output it).
Note: The ordering of the chunks being output must be the same as input
}
Run Code Online (Sandbox Code Playgroud)
所以,主要的事情我不知道该怎么做:
非常感谢对这四颗子弹的任何帮助.由于我是一个超级菜鸟,代码样本会有很大帮助.
(旁注:创建一个线程数组只是我的一个想法,处理用户定义的线程数.如果你有更好的方法来处理这个,欢迎你提出它!)
我有一个全局变量,X.然后我从子中分叉并修改X. 我希望这些更改显示在父级中,但我不希望父级必须等待子级.
我怎样才能做到这一点?
我有以下页面:
我的表单代码如下所示:
<div class="container">
<div class="row">
<div class="offset3 span3">
<form class="form-horizontal" id="inputForm">
<div class="control-group">
<label class="control-label" for="volume">Beer Volume</label>
<div class="controls">
<div class="input-append">
<input type="text" id="volume" placeholder="i.e. 16">
<span class="add-on">oz</span>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="alcPercent">Alcohol</label>
<div class="controls">
<div class="input-append">
<input type="text" id="alcPercent" placeholder="i.e. 6.3">
<span class="add-on">%</span>
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<button class="btn-large" type="button" value="CONVERT" onclick="onSubmit()">CONVERT</button>
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建页面,以便"oz"实际上是一个下拉菜单,用户可以选择"oz","centiliters","liters"等.有没有办法干净地完成这个引导?我看到有一个"按钮下拉":http://twitter.github.io/bootstrap/base-css.html#forms,但是当我复制该代码时,我无法获得任何下拉选项.
我怎样才能做到这一点?
c++ ×3
arrays ×1
c ×1
dynamic ×1
fork ×1
java ×1
list ×1
namespaces ×1
parameters ×1
process ×1
python ×1
static ×1
types ×1
write-error ×1