5 messages in com.mysql.lists.plusplusRe: problem with SSQLS in header file...
FromSent OnAttachments
Joe Hudson17 Apr 2007 17:31 
Matt Dargavel18 Apr 2007 08:29 
Warren Young18 Apr 2007 13:25 
Joe Hudson18 Apr 2007 14:24 
everweb21 Jun 2007 15:31 
Subject:Re: problem with SSQLS in header files...
From:everweb (rup@everweb.com)
Date:06/21/2007 03:31:26 PM
List:com.mysql.lists.plusplus

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 it 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 in 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 '_table' 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: #define MYSQLPP_SSQLS_NO_STATICS

From what I can see of your code, you would put the following into dbaccess.h: #include <mysql++.h> #define MYSQLPP_SSQLS_NO_STATICS #include "trade_row.h"

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";