[odb-users] Question about type conversion in "Hello" example

Rudy Depena rudy.depena at gmail.com
Thu Jan 7 02:06:49 EST 2016


I noticed that ~\odb-examples-2.4.0\hello\driver.cxx file has some lines
for persistence of a person object ...

*unsigned long john_id, joe_id;*


*john_id = db->persist(john);*

In database.ixx we can see that the persist() function is defined as

*template <typename T>*

*  inline typename object_traits<T>::id_type database::*

*  persist (T& obj)*

*  {*

*    return persist_<T, id_common> (obj);*

*  }*

I can see that while the return type for persist() is *typename
object_traits<T>::id_type*, the type of john_id is unsigned long. How is
this not a compiler error such as the following?

 "Error: No suitable conversion function from
"odb::access::object_traits<person>::id_type" to "unsigned long" exists"

What is being done to implicitly convert the id_type to an unsigned long?



P.S. - I am looking at the hello example in examples-sqlite-vc12 solution
for Windows.

More information about the odb-users mailing list