 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jakob Reuter Guest
|
Posted: Sun Sep 28, 2003 10:36 pm Post subject: Templates |
|
|
Hi,
i am working on a generic BinTrie class, and i got a problem :/...
Error:
main.cpp:37: error: request for member 'insert' in 'Trie()', which is of
non-aggregate of Type 'BinT()()'
Code:
main.cpp:
....
36 BinT Trie();
37 Trie.insert();
BinTrie.h:
typedef std::vector<bool> BitString;
template<class T=char,class Key=BitString> class BinTrie
{
public:
typedef Key key_type;
typedef T mapped_type;
typedef std::pair<mapped_type,const key_type> value_type;
iterator insert();
...
};
typedef BinTrie<char,BitString> BinT;
#include "BinTrie.cxx"
BinTrie.cxx
template<class T,class Key>
BinTrie<T,Key>::BinTrie(){}
template<class T,class Key>
BinTrie<T,Key>::~BinTrie(){}
template<class T,class Key>
class BinTrie<T,Key>::iterator BinTrie<T,Key>::insert(){
cout << "insert" << endl;
}
It seems that i messed something up with the template initialisation but i
am not sure what??
thx for any clue
cheers
Jakob
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Dietmar Kuehl Guest
|
Posted: Mon Sep 29, 2003 9:35 pm Post subject: Re: Templates |
|
|
Jakob Reuter wrote:
| Quote: | template<class T,class Key
class BinTrie
^^^^^ |
This should read "typename" instead: the keywords "typename" and
"class" are only interchangable in the declaration of the template
parameters. In this context, they are definitely not interchangable.
--
<mailto:dietmar_kuehl (AT) yahoo (DOT) com> <http://www.dietmar-kuehl.de/>
Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.com/>
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Sebastian Kapfer Guest
|
Posted: Mon Sep 29, 2003 9:37 pm Post subject: Re: Templates |
|
|
On Sun, 28 Sep 2003 18:36:41 -0400, Jakob Reuter wrote:
| Quote: | Code:
main.cpp:
...
36 BinT Trie();
|
This line of code declares a function called "Trie" which takes no
arguments and returns a BinT.
Remove the parentheses and it will do what you intended.
BinT Trie;
Another possibility:
BinT Trie = BinT(); // initialize Trie from a
// default-constructed BinT
| Quote: | main.cpp:37: error: request for member 'insert' in 'Trie()', which is of
non-aggregate of Type 'BinT()()'
^^^^ |
Note the two pairs of parentheses, indicating a function reference.
--
Best Regards, | Wer Windows-Rechner ins Internet lässt,
Sebastian | braucht nicht über SWEN stänkern!
| Quote: | --------------------------------------------------------
mailbox in "From" silently drops any mail > 20k
|
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ulrich Eckhardt Guest
|
Posted: Mon Sep 29, 2003 9:56 pm Post subject: Re: Templates |
|
|
Jakob Reuter wrote:
| Quote: | i am working on a generic BinTrie class, and i got a problem :/...
|
You mean a 'tree', no?
| Quote: | main.cpp:
...
36 BinT Trie();
|
This is the declaration of a function called 'Trie', taking no parameters
and returning a 'BinT'. What you want is
BinT Trie;
cheers
Uli
--
Questions ?
see C++-FAQ Lite: http://parashift.com/c++-faq-lite/ first !
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|