小编Zer*_*can的帖子

基于C++模板指针到成员的属性实现的一些麻烦

我的目标是在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)

c++ templates properties

4
推荐指数
1
解决办法
247
查看次数

"在objective-c上下文中,在非成员函数中使用'this'无效?

使用Xcode.

在这段代码中(func在接口中声明),告诉subj错误,站在带有'self'的字符串上.

+ (void) run: (Action) action after: (int) seconds 
{
    [self run:action after:seconds repeat:NO];
}
Run Code Online (Sandbox Code Playgroud)

什么......?

objective-c this self ios

2
推荐指数
1
解决办法
1102
查看次数

标签 统计

c++ ×1

ios ×1

objective-c ×1

properties ×1

self ×1

templates ×1

this ×1