이의 우리가 C++ 코드 다음 있다고 가정 해 봅시다 매개 변수 : 그것은 완벽한되는 지금까지 매우 간단하고있어얻기 프로토콜은
struct ISomeInterface
{
virtual ~ISomeInterface() {}
virtual void f() = 0;
};
class SomeClass : public ISomeInterface
{
public:
void f() override
{
std::cout << "Hi";
}
};
void getObject(ISomeInterface*& ptr)
{
ptr = new SomeClass;
}
int main()
{
ISomeInterface* p(nullptr);
getObject(p);
p->f();
delete p;
}
,하지만 그림을 그립니다 : 포인터를 가져 오는 인터페이스 객체에 via 함수의 매개 변수.
Objective C 프로토콜을 사용하여 동일한 결과를 얻으려면 어떻게해야합니까?
@protocol SomeProtocol <NSObject>
- (void)f;
@end
@interface SomeClass : NSObject<SomeProtocol>
- (void)f;
@end
@implementation SomeClass
- (void)f { NSLog(@"Hi"); }
@end
미리 감사드립니다.
그래, 실제로, 효과가 있었다. 객관적인 것 - c 특정 없음. 고맙습니다 –