我正在为必须检查父方法的方法编写装饰器(在我正在装饰的类的父级中使用相同名称的方法).
示例(来自PEP 318的第四个示例):
def returns(rtype):
def check_returns(f):
def new_f(*args, **kwds):
result = f(*args, **kwds)
assert isinstance(result, rtype), \
"return value %r does not match %s" % (result,rtype)
return result
new_f.func_name = f.func_name
# here I want to reach the class owning the decorated method f,
# it should give me the class A
return new_f
return check_returns
class A(object):
@returns(int)
def compute(self, value):
return value * 3
Run Code Online (Sandbox Code Playgroud)
所以我正在寻找代码#代替我想要的代码......
谢谢.
我使用的是iphone_sdk_3.0_beta_5__9m2735 SDK.当我尝试使用模拟器3.0选项编译我的代码时,我得到以下错误.代码编译为休息所有模拟器选项,即2.0,2.1,2.2,2.2.1编译我的代码时,我得到以下错误
from /Users/videomac/manish/EXPLab/2009-05-27-11-20 myApp_LL_2/myApp_Prefix.pch:7: In file included from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:30, /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UILocalizedIndexedCollation.h:11: error: syntax error before 'AT_NAME' token /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UILocalizedIndexedCollation.h:19: error: syntax error before '}' token /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UILocalizedIndexedCollation.h:21: fatal error: method definition not in @implementation context
错误位于文件UILocalizedIndexedCollation.h,这是SDK文件.我正在使用SDK 3.0的UIKit Framework.任何人都可以告诉我该怎么做才能删除此错误?
我正在从反汇编中调试一些代码(没有可用的源代码),并且有许多指令通过ds段寄存器访问数据,例如这样的:
66 3B 05 8A B1 43 00 cmp ax,word ptr ds:[43B18Ah]
Run Code Online (Sandbox Code Playgroud)
你如何让 Visual Studio 调试器告诉你ds段寄存器的偏移量,以便我可以检查它所指的内存?Watch 窗口似乎不接受像ds:[0x43B18A]或变体这样的表达式;它会告诉我那ds是 0,但这并没有告诉我段 0 的偏移量是多少。
是否有一些特殊的语法,或者这是 VS 无法做到的?使用其他调试器(例如 WinDbg 或 ntsd)会更好吗?
我正在尝试使用 emacs 23.1.1 对cc-mode 5.31.3进行字节编译,如下所示:
$ emacs -batch --no-site-file -q -f batch-byte-compile *.el
Run Code Online (Sandbox Code Playgroud)
但是其中两个文件无法编译(除了大量警告之外):
在 c-init-language-vars-for 中: cc-mode.el:168:10:Warning: 在运行时调用 cl 包中的函数“mapcan” cc-mode.el:168:10:Warning: 在运行时调用 cl 包中的函数“mapcan” cc-mode.el:162:53:Warning: 在运行时调用 cl 包中的函数“mapcan” cc-mode.el:162:53:Warning: 在运行时调用 cl 包中的函数“mapcan” cc-mode.el:163:53:Warning: cl 包中的函数 `mapcan' 在运行时调用 cc-mode.el:163:53:Warning: cl 包中的函数 `mapcan' 在运行时调用 cc-mode.el:164:53:Warning: 在运行时调用 cl 包中的函数“mapcan” cc-mode.el:164:53:Warning: 在运行时调用 cl 包中的函数“mapcan” cc-mode.el:165:53:Warning: 在运行时调用 cl 包中的函数“mapcan” cc-mode.el:165:53:Warning: 在运行时调用 cl 包中的函数“mapcan” cc-mode.el:166:53:Warning: 在运行时调用 cl 包中的函数“mapcan” cc-mode.el:166:53:Warning: 在运行时调用 cl 包中的函数“mapcan” cc-mode.el:167:53:Warning: 在运行时调用 cl 包中的函数“mapcan” cc-mode.el:167:53:Warning: 在运行时调用 cl 包中的函数“mapcan” cc-mode.el:562:4:Error: 错误的类型参数:sequencep, t …
C++规范是否允许非虚拟类的实例包含vtable指针的内存?我问这个,因为一位同事说他曾经使用过C++编译器,其中发生了以下情况:
class MyClass
{
public:
HeaderStruct header; //This had extra words
BodyStruct message_body;
};
Run Code Online (Sandbox Code Playgroud)
然后他将代码更改为此,删除了额外的单词:
struct MyClass
{
HeaderStruct header; //This did not have extra words
BodyStruct message_body;
};
Run Code Online (Sandbox Code Playgroud)
这些类型都不是虚拟的,也不是虚拟的.所以理论上可能这个特定的编译器为类实例分配了vptr的内存,但是没有为struct实例分配内存.所以我只想确定规范是否排除了这种编译器行为.
谢谢!
肯
目前我正在使用C++环境开展非常基本的游戏.这个游戏曾经是一个学校项目,但现在我完成了这个编程课程,我想扩展我的技能,并在这个旧任务上更加蓬勃发展.
我已经做了很多我很满意的改变.我已将所有数据集中到文件夹层次结构中,我已经获得了读取这些位置的代码.
然而,我的问题源于一个非常根本的缺陷,一直困扰着我.
为了访问我正在使用的图像数据,我使用了代码:
string imageLocation = "..\\DATA\\Images\\";
string bowImage = imageLocation + "bow.png";
Run Code Online (Sandbox Code Playgroud)
问题是,当玩家在游戏板上拿起一个项目时,我的代码应该使用代码:
hud.addLine("You picked up a " + (*itt)->name() + "!");
Run Code Online (Sandbox Code Playgroud)
打印到命令行,"你拿起一把弓!".但相反它显示"你选择了..\DATA\Images \!".
在集中我以前使用的数据之前:
name_(item_name.substr(0, item_name.find('.')))
Run Code Online (Sandbox Code Playgroud)
在我的Item类构造函数中将项目名称切割为bow或candle之类的东西.在我改变了数据结构的方式后,我意识到我必须改变我将名字砍成同样简单的'bow'或'candle'的方式.
我已经更改了上面的代码以反映我对数据结构的更改:
name_(item_name.substr(item_name.find("..\\DATA\\Images\\"), item_name.find(".png")))
Run Code Online (Sandbox Code Playgroud)
但不幸的是,正如我早些时候提到的那样,代码的更改并不像我计划的那样好.
所以现在我已经给出了我的问题的真正冗长的介绍,这是我的问题.
如何在两个不需要的部分之间提取字符串的中间部分?另外,作为目标的中间部分长度未知.
非常感谢你们给予的任何帮助.如果您需要更多信息,请询问; 我将非常乐意上传部分甚至整个代码以获得更多帮助.再次非常感谢你.
如果有目标文件,如何在该目标文件的数据段中获取全局变量的初始化值?例如,说我已经完成以下工作:
# I'm interested in the variable foo inside bar.o in libbar.a:
$ ar -x libbar.a bar.o
$ nm --print-size bar.o | grep foo
00000048 00000004 D foo
Run Code Online (Sandbox Code Playgroud)
这告诉我foo在大小为4的数据段中的偏移量为0x48,但是如何获取加载时获得的实际初始化值呢?
我将cpp代码移植到Objective C中.
在cpp我们可以添加一个类作为friend class另一个类,并使用其所有的公共函数和变量.
我知道这个Objective C does not support friend class概念.
如何在Objective C中将类作为另一个类的朋友
我应该如何从模板类方法中调用已定义类中的方法?以下是我的情景 -
模板类
template <class T>
class TC {
void myTemplateMethod() {
T.myMethod(); //can I call like this ?
}
};
Run Code Online (Sandbox Code Playgroud)定义的类
class tdef {
void myMethod() {
//does something
}
};
Run Code Online (Sandbox Code Playgroud)主要
int main() {
TC<tdef> tobj;
tobj.myTemplateMethod(); //can I call tdef.myMethod() like this?
}
Run Code Online (Sandbox Code Playgroud)请注意,我已经调试了这样的代码,并且发现tdef.myMethod()在这样调用时不起作用.还有什么机会在从Template类方法中调用tdef.myMethod()时不处理某些异常?
-Somnath
数组需要在编译时定义大小.有没有可能在运行时使用malloc或者其他什么来定义数组的大小?