#include <string>
#include <iostream>
namespace test
{
class AppDatabase;
class IDatabase
{
public:
template<typename T>
void bind(IDatabase& db, T& col)
{
std::cout << "binding col='" << col << "' ..." << std::endl;
}
};
class AppDatabaseHelper: public IDatabase
{
public:
class NoParams
{
};
template <typename Row, typename Params = NoParams,
typename DataBase = AppDatabase>
class ReadOnlyCursor;
template <typename Row, typename Params = NoParams,
typename Database = AppDatabase,
typename Cursor = ReadOnlyCursor<Row, Params, Database> >
class Traits
{
public:
typedef Row RowType;
typedef Params ParamsType;
typedef Database DatabaseType;
typedef Cursor CursorType;
typedef Traits<Row, Params, Database, Cursor> TraitsType;
static TraitsType traits;
std::string query;
Traits(std::string data): query(data) {}
void bind(Database& db, const Params& row) const;
};
};
class AppDatabase: public AppDatabaseHelper
{
public:
};
} // namespace test
// In the .cpp file.
namespace test
{
using namespace std;
struct Row
{
string id;
int i;
};
struct Params
{
Params(string s): id(s)
{
}
string id;
};
AppDatabase::Traits<Row, Params, AppDatabase>
AppDatabase::Traits<Row, Params, AppDatabase>::traits(
"SELECT id, i FROM table WHERE id = ?");
void
AppDatabase::Traits<Row, Params, AppDatabase>::
bind(AppDatabase& db, const Params& params) const
{
db.bindParams(params.id);
}
}
Mike
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
If this is supposed to be an explicit member instantiation, you
need the magic
template<>
in front of it.
> void
> AppDatabase::Traits<Row, Params, AppDatabase>::
> bind(AppDatabase& db, const Params& params) const
> {
> db.bindParams(params.id);
> }
> }
Same problem here. (As a side note: The implementation looks
suspecious,
because there is no AppDatabase.bindParams ins sight).
HTH & Greetings from Bremen,
Daniel Krügler