jjb*_*bss 0 c++ static class static-members
我有以下代码:
class SSLHashSHA1
{
SSLHashSHA1();
~SSLHashSHA1();
public:
static OSStatus update(string*, int*);
static OSStatus final (string*, string*);
};
OSStatus SSLHashSHA1::update(string* ctx, int* ran){
return 0;
}
OSStatus SSLHashSHA1::final(string* ctx, string* out){
return 0;
}
static OSStatus SSLVerifySignedServerKeyExchange(
SSLContext *ctx, bool isRsa, SSLBuffer signedParams, uint8_t *signature, uint16_t signatureLen)
{
OSStatus err;
if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0)
goto fail;
if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
goto fail;
goto fail;
if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0)
goto fail;
fail:
SSLFreeBuffer(&signedHashes);
SSLFreeBuffer(&hashCtx);
return err;
}
Run Code Online (Sandbox Code Playgroud)
我得到了标题中提到的错误。我得到了 SSLHashSHA1.update 和 SSLHashSHA1.final 调用。为什么我会得到那个?
我认为当我将类成员函数设为静态时,我可以使用它而无需创建对象。或者我应该将类更改为结构或类似的东西?
SSLHashSHA1.update()
Run Code Online (Sandbox Code Playgroud)
这是完全错误的,SSLHashSHA1
是一个类,而不是一个实例,所以你不能在.
这里使用运算符来调用一个方法,相反,正如你所提到的,你update
是一个静态函数,因此使用范围解析运算符(::
) 像这样 :
SSLHashSHA1::update(&hashCtx, &serverRandom))
Run Code Online (Sandbox Code Playgroud)