什么是pythonic方法从文件中读取一行而不是前进到文件中的位置?
例如,如果您有一个文件
cat1
cat2
cat3
Run Code Online (Sandbox Code Playgroud)
而你file.readline()会得到你cat1\n.接下来file.readline()会回来cat2\n.
有一些功能,例如file.some_function_here_nextline()让cat1\n您可以稍后做file.readline(),并取回cat1\n?
std::function<>当C++ 11不可用时,应该使用什么构造作为代理?
替代应该基本上允许从另一个类访问一个类的私有成员函数,如下例所示(不使用std :: function的其他功能).类Foo是固定的,不能改变太多,我只能访问类Bar.
class Foo {
friend class Bar; // added by me, rest of the class is fixed
private:
void doStuffFooA(int i);
void doStuffFooB(int i);
};
class Bar {
public:
Bar( Foo foo, std::function< void (const Foo&, int) > func ) {
myFoo = foo;
myFooFunc = func;
};
private:
doStuffBar( const &Foo foo ) {
myFooFunc( foo, 3 );
}
Foo myFoo;
std::function< void (const Foo&, int) > myFooFunc;
}
int main() {
Foo foo(...); …Run Code Online (Sandbox Code Playgroud)