我在头文件中遇到了以下代码:
class Engine
{
public:
void SetState( int var, bool val );
{ SetStateBool( int var, bool val ); }
void SetState( int var, int val );
{ SetStateInt( int var, int val ); }
private:
virtual void SetStateBool(int var, bool val ) = 0;
virtual void SetStateInt(int var, int val ) = 0;
};
Run Code Online (Sandbox Code Playgroud)
对我来说,这意味着Engine
从它派生的类或类必须为那些纯虚函数提供实现.但我不认为派生类可以访问这些私有函数以重新实现它们 - 那么为什么要将它们变为虚拟?
我有一个表示dos路径的字符串变量,例如:
var = "d:\stuff\morestuff\furtherdown\THEFILE.txt"
我想将此字符串拆分为:
[ "d", "stuff", "morestuff", "furtherdown", "THEFILE.txt" ]
我已经尝试使用split()
和replace()
,但他们要么只处理第一个反斜杠或者插入十六进制数字串入.
我需要以某种方式将此字符串变量转换为原始字符串,以便我可以解析它.
最好的方法是什么?
我还应该补充一点,var
即我试图解析的路径的内容实际上是命令行查询的返回值.这不是我自己生成的路径数据.它存储在一个文件中,命令行工具不会逃避反斜杠.
我有一个叫做的类Action
,它实际上是一个围绕Move
对象deque的包装器.
因为我需要遍历Moves
前向和后向的双端队列,所以我有一个前向迭代器和一个reverse_iterator作为类的成员变量.这样做的原因是因为当我前往或后退时,我需要知道何时离开了双端队的"终点".
这个类看起来像这样:
class Action
{
public:
SetMoves(std::deque<Move> & dmoves) { _moves = dmoves; }
void Advance();
bool Finished()
{
if( bForward )
return (currentfwd==_moves.end());
else
return (currentbck==_moves.rend());
}
private:
std::deque<Move> _moves;
std::deque<Move>::const_iterator currentfwd;
std::deque<Move>::const_reverse_iterator currentbck;
bool bForward;
};
Run Code Online (Sandbox Code Playgroud)
该Advance
功能如下:
void Action::Advance
{
if( bForward)
currentfwd++;
else
currentbck++;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,我希望能够检索当前Move
对象的迭代器,而无需查询我是向前还是向后.这意味着一个函数返回一种类型的迭代器,但我有两种类型.
我应该忘记返回一个迭代器,并返回一个Move
对象的const引用 吗?
最好的祝愿,
BeeBand
我正在使用libcurl,并且在VC++ 10中遇到以下类型的链接器错误.
1>main.obj : error LNK2019: unresolved external symbol __imp__curl_easy_strerror referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl curl_httpget(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?curl_httpget@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV12@@Z)
Run Code Online (Sandbox Code Playgroud)
如何摆脱函数名称前面的imp前缀?我链接到正确的lib,正确的路径等.
我理解Dijkstra的算法是什么,但我不明白为什么它的工作原理.
当选择下一个要检查的顶点时,为什么Dijkstra算法会选择权重最小的顶点?为什么不随意选择一个顶点,因为算法无论如何都会访问所有顶点?
pixel_data
是vector
的char
.
当我这样做时,printf(" 0x%1x ", pixel_data[0] )
我期待着看到0xf5
.
但我觉得0xfffffff5
我打印出一个4字节的整数而不是1字节.
为什么是这样?我给printf
了一个char
打印输出 - 它只有1个字节,为什么printf
打印4?
NB.在printf
实现包裹第三方API内,但只是想知道,这是标准的功能printf
?
我在python中迭代一个数组:
for g in [ games[0:4] ]:
g.output()
Run Code Online (Sandbox Code Playgroud)
我是否还可以在该for
循环中初始化和递增索引并将其传递给g.output()
?
这g.output(2)
导致:
Game 2 - ... stuff relating to the object `g` here.
Run Code Online (Sandbox Code Playgroud) 我试图.c
使用Python 查找目录中的所有文件.
我写了这个,但它只是将所有文件归还给我 - 而不仅仅是.c
文件.
import os
import re
results = []
for folder in gamefolders:
for f in os.listdir(folder):
if re.search('.c', f):
results += [f]
print results
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得.c
文件?