[odb-users] Missing include in generated code

Dieter Govaerts dieter.govaerts at bricsys.com
Wed Sep 13 10:07:26 EDT 2017


Consider following example:

// objects.h
#ifndef OBJECTS_H
#define OBJECTS_H

#include <memory>
#include <string>
#include <vector>

#pragma db namespace() pointer(std::shared_ptr)

#pragma db object
struct Employee
	#pragma db id
	unsigned id_;
	std::string name_;
using EmployeePtr = std::shared_ptr<Employee>;
using Employees = std::vector<EmployeePtr>;

#pragma db object
struct Company
	#pragma db id
	unsigned id_;
	std::string name_;
	Employees employees_;

#endif // OBJECTS_H

#ifndef VIEWS_H
#define VIEWS_H

#include "objects.h"

#pragma db view object(Company) object(Employee)
struct CompanyEmployeeView
	EmployeePtr employee;

#endif // VIEWS_H

Compile with:
odb --std c++11 --database sqlite --generate-query objects.h views.h

Then I get following errors when compiling with visual studio 12:
C:\Dev\thirdparty\libodb\include\odb/sqlite/statement-cache.txx(33) : error C2440: 'static_cast' : cannot convert from 'odb::sqlite::statements_base' to 'statements_type &'
        static_cast and safe_cast to reference can only be used for valid initializations or for lvalue casts between related classes
        views-odb.cxx(115) : see reference to function template instantiation 'odb::access::object_traits_impl<Employee,id_sqlite>::statements_type &odb::sqlite::statement_cache::find_object<employee_object_type>(void)' being compiled
C:\Dev\thirdparty\libodb\include\odb/sqlite/statement-cache.txx(36) : error C2514: 'odb::sqlite::object_statements<odb::access::object_traits<Employee>::object_type>' : class has no constructors

I can fix it by adding this include to "objects-odb.hxx":
#include <odb/sqlite/simple-object-statements.hxx>

The error doesn't occur when defining both objects and the view in the same header.


More information about the odb-users mailing list