Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C++ template compile error on g++ 4.1.2

26 views
Skip to first unread message

Mike

unread,
Aug 17, 2010, 3:57:35 AM8/17/10
to
Can anyone explain to me why the following code doesn't compile (I
stripped it down from a larger multi-file application). Is this a
problem with the compiler or me :-):
/*
* Below is a example showing the problem I'm having trying to compile under
* gcc 4.1.2 on Red Hat Enterprise Linux release 5.3 (Final). I get the
* following compile errors:
*
* What am I doing wrong?
*
* test/TestCase.cpp:97: error: too few template-parameter-lists
* test/TestCase.cpp:102: error: too few template-parameter-lists
*
* Mike
*/

#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! ]

Daniel Krügler

unread,
Aug 17, 2010, 1:38:19 PM8/17/10
to

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

0 new messages