2013/10/17 Wim Dumon <w...@emweb.be>

> Hi,
>
> The issue here is indeed that A.h has to include B.h and B.h has to
> include A.h, which will not work, by C++'s preprocessor design. There's two
> possible ways around this:
>
> 1. don't use the typedefs, and only forward declare 'class Country;' in
> City.h and 'class City;' in Country.h
>
> 2. put the forward declaration and typedefs in a separate file (MyFwd.h),
> and include that file in ever Dbo file.
>
> BR,
> Wim.
>
>
>
> 2013/10/17 Muhammad Nasser Al-Noimi <mnno...@gmail.com>
>
>> 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
>>
>
>
>
> ------------------------------------------------------------------------------
> 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
>
>
------------------------------------------------------------------------------
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