By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,502 Members | 1,620 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,502 IT Pros & Developers. It's quick & easy.

Whats wrong with this class template? (compilation errors)

P: n/a
template <typename T1, typename T2>
struct MyDbInfo
{
MyDbInfo():m_pEnv(0), m_tran(0), m_db(0), m_idx(0)
{}

MyDbInfo(CDbEnv *env, DbTxn* tran, T1* db_ptr, T2
*idx_ptr):m_pEnv(env), m_tran(tran), m_db(db_ptr), m_idx(idx_ptr)
{}

~MyDbInfo()
{
delete m_pEnv ;
delete m_tran ;
delete m_db ;
delete m_idx ;
}

T1 * GetDbHandle() const { return m_db ;}

private:
CDbEnv* m_pEnv = 0;
DbTxn* m_tran = 0;
T1 * m_db = 0;
T2 * m_idx = 0 ;
};
I get the following errors:

Compiling...
simple_test.cpp
c:\test\bdb.h(47) : error C2143: syntax error : missing ')' before '*'
c:\test\bdb.h(65) : see reference to class template
instantiation 'MyDbInfo<T1,T2>' being compiled
c:\test\bdb.h(47) : error C2143: syntax error : missing ';' before '*'
c:\test\bdb.h(47) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
c:\test\bdb.h(47) : error C2143: syntax error : missing ';' before '*'
c:\test\bdb.h(47) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
c:\test\bdb.h(47) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
c:\test\bdb.h(47) : error C2143: syntax error : missing ';' before '*'
c:\test\bdb.h(47) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
c:\test\bdb.h(47) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
c:\test\bdb.h(47) : error C2143: syntax error : missing ';' before '*'
c:\test\bdb.h(47) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
c:\test\bdb.h(47) : error C2059: syntax error : ')'
c:\test\bdb.h(47) : error C2065: 'env' : undeclared identifier
c:\test\bdb.h(47) : error C3861: 'm_pEnv': identifier not found
c:\test\bdb.h(47) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
c:\test\bdb.h(47) : error C2061: syntax error : identifier 'tran'
c:\test\bdb.h(47) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
c:\test\bdb.h(47) : error C2061: syntax error : identifier 'db_ptr'
c:\test\bdb.h(47) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
c:\test\bdb.h(47) : error C2061: syntax error : identifier 'idx_ptr'
c:\test\bdb.h(48) : error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
c:\test\bdb.h(48) : error C2143: syntax error : missing ';' before '{'
c:\test\bdb.h(48) : error C2334: unexpected token(s) preceding '{';
skipping apparent function body
c:\test\bdb.h(65) : fatal error C1004: unexpected end-of-file found
Nov 11 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Correction:

template <typename T1, typename T2>
struct MyDbInfo
{
MyDbInfo():m_pEnv(0), m_tran(0), m_db(0), m_idx(0)
{}

MyDbInfo(CDbEnv *env, DbTxn* tran, T1* db_ptr, T2
*idx_ptr):m_pEnv(env), m_tran(tran), m_db(db_ptr), m_idx(idx_ptr)
{}

~MyDbInfo()
{
delete m_pEnv ;
delete m_tran ;
delete m_db ;
delete m_idx ;
}

T1 * GetDbHandle() const { return m_db ;}

private:
CDbEnv* m_pEnv ;
DbTxn* m_tran ;
T1 * m_db ;
T2 * m_idx ;
};
Nov 11 '08 #2

P: n/a
On Tue, 11 Nov 2008 15:43:02 +0000, (2b|!2b)==? wrote:
Correction:

template <typename T1, typename T2>
struct MyDbInfo
{
MyDbInfo():m_pEnv(0), m_tran(0), m_db(0), m_idx(0) {}

MyDbInfo(CDbEnv *env, DbTxn* tran, T1* db_ptr, T2
*idx_ptr):m_pEnv(env), m_tran(tran), m_db(db_ptr), m_idx(idx_ptr)
{}

~MyDbInfo()
{
delete m_pEnv ;
delete m_tran ;
delete m_db ;
delete m_idx ;
}

T1 * GetDbHandle() const { return m_db ;}

private:
CDbEnv* m_pEnv ;
DbTxn* m_tran ;
T1 * m_db ;
T2 * m_idx ;
};
Compiles fine with the following typedefs:

typedef int CDbEnv;
typedef int DbTxn;

--
OU
Remember 18th of June 2008, Democracy died that afternoon.
http://frapedia.se/wiki/Information_in_English
Nov 11 '08 #3

P: n/a
(2b|!2b)==? wrote:
template <typename T1, typename T2>
struct MyDbInfo
{
MyDbInfo():m_pEnv(0), m_tran(0), m_db(0), m_idx(0)
{}

MyDbInfo(CDbEnv *env, DbTxn* tran, T1* db_ptr, T2
*idx_ptr):m_pEnv(env), m_tran(tran), m_db(db_ptr), m_idx(idx_ptr)
{}

~MyDbInfo()
{
delete m_pEnv ;
delete m_tran ;
delete m_db ;
delete m_idx ;
}

T1 * GetDbHandle() const { return m_db ;}

private:
CDbEnv* m_pEnv = 0;
DbTxn* m_tran = 0;
T1 * m_db = 0;
T2 * m_idx = 0 ;
};
I get the following errors:

Compiling...
simple_test.cpp
c:\test\bdb.h(47) : error C2143: syntax error : missing ')' before '*'
c:\test\bdb.h(65) : see reference to class template
instantiation 'MyDbInfo<T1,T2>' being compiled
[..]
Please next time indicate *which line* in the code you posted is the one
the compiler complains about. Don't post line numbers, just add the
comment to the line (47 in this case) that would say "this is line 47".
Otherwise, how the hell are we supposed to know? And while you're at
it, read the FAQ, especially section 5. I know you probably already
have. So, refresh it then.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 11 '08 #4

P: n/a
(2b|!2b)==? wrote:
template <typename T1, typename T2>
struct MyDbInfo
{
MyDbInfo():m_pEnv(0), m_tran(0), m_db(0), m_idx(0)
{}

MyDbInfo(CDbEnv *env, DbTxn* tran, T1* db_ptr, T2
*idx_ptr):m_pEnv(env), m_tran(tran), m_db(db_ptr), m_idx(idx_ptr)
{}

~MyDbInfo()
{
delete m_pEnv ;
delete m_tran ;
delete m_db ;
delete m_idx ;
}

T1 * GetDbHandle() const { return m_db ;}

private:
CDbEnv* m_pEnv = 0;
DbTxn* m_tran = 0;
T1 * m_db = 0;
T2 * m_idx = 0 ;
};
I get the following errors:

Compiling...
simple_test.cpp
c:\test\bdb.h(47) : error C2143: syntax error : missing ')' before '*'
c:\test\bdb.h(65) : see reference to class template
'CDbEnv' and 'DbTxn' are undefined. This code doesn't
have 47 lines, though, which is why I don't if that's
your problem.
[...]
Schobi
Nov 11 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.