小编JAt*_*dar的帖子

在golang中扩展包结构

是否有可能在golang extend struct(类似于在其他语言中扩展一个类,并将其与旧函数一起使用)

我有https://github.com/xanzy/go-gitlab/blob/master/services.go#L287类型SetSlackServiceOptions

package gitlab

// SetSlackServiceOptions struct
type SetSlackServiceOptions struct {
    WebHook  *string `url:"webhook,omitempty" json:"webhook,omitempty" `
    Username *string `url:"username,omitempty" json:"username,omitempty" `
    Channel  *string `url:"channel,omitempty" json:"channel,omitempty"`
}
Run Code Online (Sandbox Code Playgroud)

我想在我自己的包中添加一些字段.有可能这样做,我可以用我自己的新类型调用函数SetSlackService吗?

package gitlab

func (s *ServicesService) SetSlackService(pid interface{}, opt *SetSlackServiceOptions, options ...OptionFunc) (*Response, error) {
    project, err := parseID(pid)
    if err != nil {
        return nil, err
    }
    u := fmt.Sprintf("projects/%s/services/slack", url.QueryEscape(project))

    req, err := s.client.NewRequest("PUT", u, opt, options)
    if err != nil {
        return nil, err
    }

    return s.client.Do(req, …
Run Code Online (Sandbox Code Playgroud)

struct go

5
推荐指数
1
解决办法
8432
查看次数

C++自己的迭代器

我的c ++代码有点问题.我有链表(下图),我需要为自己的(学校工作)制作一个迭代器..

列表http://www.attanon.eu/list.png

我在list列表变量中包含head,last和actual节点.

我的类迭代器就是这个

class iterator
{
    Node* _node;
public:
    iterator(Node* node) : _node(node){}
    ~iterator(){ _node = nullptr; }

    iterator& operator=(const iterator& other)
    {
        _node = other._node;
        return *this;
    }
    bool operator==(const iterator& other)
    {
        if (_node == nullptr || other._node == nullptr)
        {
            return false;
        }
        else
        {
            return _node->_data == other._node->_data;
        }
    }
    bool operator!=(const iterator& other)
    {
        if (_node == nullptr || other._node == nullptr)
        {
            return false;
        }
        else
        {
            return _node->_data != other._node->_data;
        } …
Run Code Online (Sandbox Code Playgroud)

c++ iterator linked-list

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

标签 统计

c++ ×1

go ×1

iterator ×1

linked-list ×1

struct ×1