是否有可能在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) 我的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)