Joe Hudson-4 wrote:
> I'd like to define a class with fetches and processes data from a DB.
> That class has methods which take and return vectors of rows of the DB,
> represented by SSQLS structures.
> The header file for this class I need in other source files so I can use
> there. Fine.
> Trouble is, when is define a struct using
> sql_create_# in the header file, I get a link error complaining about
> multiple defintions of symbols <struct name>::names
> and <struct name>::_table.
> I can't have the sql_create_# statement in the cpp file of the class (and
> have a 'struct <struct name>' forward declaration in the header)
> because then I can't dereference pointers or use iterators to that struct
> other cpp files, which is what I want to do.
> So, what's the solution? Has anyone come across this problem?
Your header file is fine. In my opinion you're doing nothing wrong - but
mysqlpp has a little hoop for you to jump through !
The mysqlpp macro defines two static variables for each struct; 'names' and
When you include the header file, you are including these static definitions
- if you include the header file in more than one cpp file, you get the
"multiple definitions" error from the linker because it finds one definition
of the static variable for each #include. There is a flag in mysqlpp which
allows you to include the header file more than once:
From what I can see of your code, you would put the following into
Note also that the static '_table' is what you would use to change the name
of the database table accessed by the mysqlpp code. For example, if you want
to change the table name to "Trade" but leave the "trade_row" class
untouched, you can add this after the includes in your dbaccess.cpp:
const char *trade_row::_table = "Trade";
View this message in context:
Sent from the MySQL - C++ mailing list archive at Nabble.com.