我已经创建了一个我的类需要实现的协议,然后将一些常见的功能分解到基类中,所以我这样做了:
@protocol MyProtocol
- (void) foo;
- (void) bar;
@end
@interface Base <MyProtocol>
@end
@interface Derived_1 : Base
@end
@interface Derived_2 : Base
@end
@implementation Base
- (void) foo{
//something foo
}
@end
@implementation Derived_1
- (void) bar{
//something bar 1
}
@end
@implementation Derived_2
- (void) bar{
//something bar 2
}
@end
Run Code Online (Sandbox Code Playgroud)
这样在我的代码中我使用通用id <MyProtocol>.
代码可以工作(只要不直接使用Base),但编译器在Base的实现结束时会发出警告:
Incomplete implementation of class Base
有没有办法避免这种警告,或者更好的是,在Objc中获得这种部分实现的抽象基类行为的更合适的方法?
使用IPv4,我可以将()绑定到特定地址,以选择将用于接收数据包的接口(在某些情况下,也可以发送,但这不是重点).
在双栈IPv6/IPV4机器上我有这个问题:我可以创建一个6套接字并使用它来接收4个流量,但如果我想绑定到特定接口,我必须选择要绑定的IP地址.
如果我绑定到IPv6地址,我将过滤掉所有IPv4流量,反之亦然.
如何从特定接口接收IPv4和IPv6流量?
这段代码不能用clang ++ 6.0或g ++ 4.9.1编译(代码没有意义,但这是实现它的最小例子):
#include <forward_list>
template<typename T>
T getItem(typename std::forward_list<T>::const_iterator it) {
return *it;
}
template<typename T>
void foo() {
std::forward_list<T> list;
auto item = getItem(list.cbegin());
}
template<typename T>
void bar(const std::forward_list<T>& list) {
auto item = getItem(list.cbegin());
}
int main() {
std::forward_list<int> list;
bar(list);
}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
t2.cpp:17:17: error: no matching function for call to 'getItem'
auto item = getItem(list.cbegin());
^~~~~~~
t2.cpp:22:5: note: in instantiation of function template specialization 'bar<int>' requested here
bar(list);
^
t2.cpp:4:3: note: candidate template …Run Code Online (Sandbox Code Playgroud)