我的目标是在C++中创建属性,就像在C#中一样 - 具有非平凡的set/get行为.这里,Property的对象持有refs来掌握prop及其set/get方法.
Property.h的实现,内容:
#include <iostream>
using namespace std;
namespace First {
template <class Master, class Type>
struct Property
{
Master &master;
const Type (Master::*&get) () const;
Type (Master::*&set)(Type value);
Property
(
Master &master,
const Type (Master::*get) () const,
Type (Master::*set)(Type value)
):
get(get),
set(set),
master(master)
{ }
operator const Type() const { cout << "inside" << endl; return (master.*get)(); }
Type operator = (Type value)
{
return (master.*set)(value);
}
};
// Test chamber.
class R
{
float x;
const …Run Code Online (Sandbox Code Playgroud) 使用Xcode.
在这段代码中(func在接口中声明),告诉subj错误,站在带有'self'的字符串上.
+ (void) run: (Action) action after: (int) seconds
{
[self run:action after:seconds repeat:NO];
}
Run Code Online (Sandbox Code Playgroud)
什么......?