有谁知道,skype如何重定向NAT和防火墙?
我正在用python实现一个跳棋游戏板.以下是我将板结构生成为[8] [8]数组的方法:
_matrix = []
for i in xrange(8):
_matrix.append( [' '] * 8 )
for row in xrange(0, 8):
for col in xrange(0, 8):
if _darkQuad(row, col) == True:
_matrix[row][col] = '#'
else:
_matrix[row][col] = '-'
def _darkQuad(row, col):
return ((row%2) == (col%2))
def _printDebugBoard():
for row in xrange(0, 8):
for col in xrange(0, 8):
print _matrix[row][col]
print ''
Run Code Online (Sandbox Code Playgroud)
这应该像我的董事会一样:
Run Code Online (Sandbox Code Playgroud)# - # - # - # - - # - # - # - # ...
但结果是:
- …Run Code Online (Sandbox Code Playgroud) 我用智能指针重写我的代码.我有这样的情况:
void Foo(SomeClass *p) { }
boost::shared_ptr<SomeClass> p(new SomeClass);
Run Code Online (Sandbox Code Playgroud)
现在该做什么:从wrapper(p.get())传递原始指针或重写函数参数并直接传递智能指针,如:
void Foo(boost::shared_ptr<Foo> obj) { }
Run Code Online (Sandbox Code Playgroud)
我不确定.据我所知,智能指针应遵循一些指针,看看它是否仍然需要在程序中.所以我们可以传递原始指针.
我有一些std :: vector,我必须使用一些默认值来调整它.这是代码:
static int Counter = 0;
class Data
{
/* ... */
Data() {
Counter++;
std::cout << Counter << std::endl;
}
};
std::vector<Data> mArray;
for (int i=0; i <= 200; ++i)
{
mArray.push_back(Data());
}
// And resizing somewhere:
std::cout << "Resizing!\n";
mArray.resize(400, Data());
Run Code Online (Sandbox Code Playgroud)
据我所知,在插入200个项目后,我可以使用resize为每个新元素获取新大小和默认值的函数来调整它.
当我运行该程序时,我看到:
0
1
2
...
199
200
Resizing
201
Run Code Online (Sandbox Code Playgroud)
为什么调整大小后只插入1个项目?
例如,我有一个c ++中的varibale:
const float Pi = 3.1415926535898f;
Run Code Online (Sandbox Code Playgroud)
使用boost.python将它导出到python-module的最佳方法是什么?
我想在全局范围内将其作为变量访问.
使用boost.python将模板函数从c ++导出到python的正确方法是什么?这是代码:
template<typename T>
T getValue(const std::string &key, const T &defaultValue = T()) {}
// Export into some python class:
class_<ConfigManager>(...)
.def("GetValue", getValue<int>)
.def("GetValue", getValue<float>)
.def("GetValue", getValue<std::string>);
Run Code Online (Sandbox Code Playgroud)
用法:
print GetValue("width")
Boost.Python.ArgumentError: Python argument types in
GetValue(ConfigManager, str)
did not match C++ signature:
GetValue(ConfigManager {lvalue}, std::string, int)
Run Code Online (Sandbox Code Playgroud)
怎么了?
我正在开发游戏.我将游戏对象存储在此地图中:
std::map<std::string, Object*> mObjects;
Run Code Online (Sandbox Code Playgroud)
std::string是在代码中进一步查找的对象的键/名称.指向某些对象非常容易,例如:mObjects["Player"] = ....但是我担心由于在该地图中的每次搜索中分配std :: string而导致速度变慢.所以我决定int用作该地图的关键.
第一个问题:那真的会更快吗?
第二,我不想删除我当前访问的对象类型,所以我找到了方法:存储crc字符串计算为关键.例如:
Object *getObject(std::string &key)
{
int checksum = GetCrc32(key);
return mObjects[checksum];
}
Object *temp = getOject("Player");
Run Code Online (Sandbox Code Playgroud)
或者这是个坏主意?为了计算crc我会用boost::crc.或者这是个坏主意,校验和的计算比使用密钥类型在地图中搜索要慢得多std::string?
我有一个存储的设置std::map.例如,有值的WorldTime键可以更新每个主循环迭代.我不想在我需要时从地图上读取它(它也在每帧处理),我认为它根本不快.那么,我可以获得指向地图值的指针并访问它吗?代码是:
std::map<std::string, int> mSettings;
// Somewhere in cycle:
mSettings["WorldTime"] += 10; // ms
// Somewhere in another place, also called in cycle
DrawText(mSettings["WorldTime"]); // Is slow to call each frame
Run Code Online (Sandbox Code Playgroud)
所以这个想法是这样的:
int *time = &mSettings["WorldTime"];
// In cycle:
DrawText(&time);
Run Code Online (Sandbox Code Playgroud)
怎么了?我应该这样做吗?
我无法让它在我的控制器中运行.代码是:
App::import('Sanitize');
class MyController extends AppController
{
public $uses = array('Sanitize');
function Foo()
{
// Fatal error: Class 'Sanitize' not found
$test = Sanitize::paranoid($data);
// Fatal error: Call to a member function paranoid() on a non-object
$test = $this->sanitize->paranoid($data);
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?