Hi,

Ihave aC++ trouble and I'm wondering if someone can help me here. Iwant 
to deal with database using Wt::Dbo. I want to put each table definition 
into a separate source file. I have OneToMany relation between two 
tables, When I put each class into separate files I got the error: 
"'Cities' does not name a type". I got no error If classes are in the 
same source file.
I wrote two classes "Country" and "City" with some helper typedefs as 
following:

//Country.h ----------------------------------------------
#ifndef COUNTRY_H
#define COUNTRY_H

#include <Wt/Dbo/Dbo>
#include <string>

#include "database.h"

namespace dbo = Wt::Dbo;

// Country
class Country;
typedef dbo::ptr<Country> CountryPtr;
typedef dbo::collection< dbo::ptr<Country> > Countries;

class Country {
public:
     Cities cities;

     template<class Action>
     void persist(Action& a)
     {
         dbo::hasMany(a, cities, dbo::ManyToOne, "country");
     }
};

#endif // COUNTRY_H

// city.h -----------------------------------------------------
#ifndef CITY_H
#define CITY_H

#include <Wt/Dbo/Dbo>
#include <string>

#include "database.h"

namespace dbo = Wt::Dbo;

// City
class City;
typedef dbo::ptr<City> CityPtr;
typedef dbo::collection< dbo::ptr<City> > Cities;

class City {
public:
     CountryPtr country;

     template<class Action>
     void persist(Action& a)
     {
         dbo::belongsTo(a, country, "country");
     }
};

#endif // CITY_H

Thanks a lot

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to