这个问题是相当理论上的,尽管有趣的是让 MS VS2010 将以下变量声明(内部main
)视为函数声明:
typedef std::shared_ptr<asymm::PrivateKey> PrivateKeyPtr;
...
void main()
{
...
maidsafe::dht::PrivateKeyPtr pk(); // I'm trying to init variable here, though it thinks it's function declaration
kNode->node()->Store(key, value, "", ttl, pk, std::bind(&StoreCallback, args::_1, key, ttl));
}
它抛出以下异常:
Error 5 error C2664: 'maidsafe::dht::Node::Store' : cannot convert parameter 5 from 'maidsafe::dht::PrivateKeyPtr (__cdecl *)(void)' to 'maidsafe::dht::PrivateKeyPtr' C:\Projects\MaidSafe-DHT\src\maidsafe\dht\demo\demo_main.cc 286 1 KademliaDemo
虽然以下几行就像一个魅力:
maidsafe::dht::PrivateKeyPtr pk = maidsafe::dht::PrivateKeyPtr();
kNode->node()->Store(key, value, "", ttl, pk, std::bind(&StoreCallback, args::_1, key, ttl));