0

This question is based on Understanding this highly templated C++ function binder

There's this declaration:

template<typename Container, typename Ret, typename ...Args>
    BindImpl<Container, Ret, Args...> DeduceImpl (Ret (Container::*)(Args...));

which isn't defined anywhere.

Then it's used like this:

(typename decltype(::AIpStack::BindPrivate::DeduceImpl(&EthIpIface::driverSendIp4Packet)) ::template Callable<&EthIpIface::driverSendIp4Packet>((this)).toFunction())

As you can see, DeduceImpl is called without being defined. I guess that, since decltype is just for knowing the type, there's no call, so the program never calls the definition.

Because of this I started to wonder: when can I declare but not define?

Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150
  • Anywhere the definition is not required? This is like asking "where can I go on vacation without having to fly". The answer is: anywhere you can reasonably travel to, without hopping on a plane. – Sam Varshavchik Jan 02 '20 at 20:47
  • @SamVarshavchik To be fair, the geography of C++ is not that easy. It is more like asking "Where can I go without changing subway more than twice in this city I have never been to before." – n314159 Jan 02 '20 at 20:49
  • Kind of circular but you only need a definition when what you are doing requires a defined thing. Basically if you ODR-use it it need to be defined. – NathanOliver Jan 02 '20 at 20:50
  • I don't think this is a duplicate of the linked question. There are more possibilities to use a type that is declared but not defined. I.e. you can declare pointers and references to this type, but this is (afaik) only useful if you define the type later. It is also used in templating. Either to do SFINAE-Magic or to make specializations possible without having a viable default case (i.e. if you only want to define a template for some specific types). – n314159 Jan 02 '20 at 20:56

0 Answers0