![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: Helltown
Posts: 162
Rep Power: 4
![]() |
C++ template classes question
#include <stdio.h>
#include <memory>
template <class _Type, int _MinLen = 32, _Type _DefValue = 0>
class dlist {
public:
_Type * items;
int length;
};
dlist<char*> motd_lines;
int main (){
return 0;
}H:\test.cpp:9: error: could not convert template argument `0' to `char*' H:\test.cpp:9: error: invalid type in declaration before ';' token Using the latest version of Dev-Cpp and whatever Mingw that came with it. My question is...what am I doing wrong here? It compiles perfectly with both VC++ 6 and 2005.
__________________
Spread your wings and fly! Chicken! |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Nov 2006
Location: 163H
Posts: 213
Rep Power: 2
![]() |
Replace the stdio with cstdio.
__________________
You never test the depth of a river with both feet. The believer is happy. The doubter is wise. Free speech carries with it some freedom to listen. The next generation will always surpass the previous one. It`s one of the never ending cycles of life. |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: Helltown
Posts: 162
Rep Power: 4
![]() |
umm ok...what was the problem?
__________________
Spread your wings and fly! Chicken! |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Nov 2006
Location: 163H
Posts: 213
Rep Power: 2
![]() |
All the C header files in C++ have a c letter before them.
__________________
You never test the depth of a river with both feet. The believer is happy. The doubter is wise. Free speech carries with it some freedom to listen. The next generation will always surpass the previous one. It`s one of the never ending cycles of life. |
|
|
|
|
|
#5 | |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: Helltown
Posts: 162
Rep Power: 4
![]() |
Well my project didn't compile in Dev-Cpp so I extracted that bit. But it sill doesn't compile. How about this?
#include <cstdio>
#include <memory>
template <class _Type, int _MinLen = 32, _Type _DevValue = 0>
class dlist {
public:
_Type * items;
int length;
_Type get(int i){
return (i >= 0 && i < length)? items[i] : _DevValue ;
}
};
dlist<char*> motd_lines;
int main (){
return 0;
}Quote:
__________________
Spread your wings and fly! Chicken! |
|
|
|
|
|
|
#6 |
|
Hobbyist
Join Date: Sep 2005
Posts: 261
Rep Power: 4
![]() |
I think pointer template arguments have to have external linkage. Presumably '0' doesn't. You'll have to do some digging.
|
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: Helltown
Posts: 162
Rep Power: 4
![]() |
Well, "dlist<int,32,5> motd_lines;" would work just fine. I'm removed the "_DevValue" parameter and it compiled just fine. Thanks everyone.
__________________
Spread your wings and fly! Chicken! |
|
|
|
|
|
#8 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 852
Rep Power: 4
![]() |
You could try using a cast to _Type around the 0 in the initialiser.
|
|
|
|
|
|
#9 |
|
Hobbyist
Join Date: Sep 2005
Posts: 261
Rep Power: 4
![]() |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Classes question | MR.T | Python | 3 | Oct 28th, 2006 9:34 PM |
| Pointers to std::strings Question (and classes in general) | Soulstorm | C++ | 3 | Aug 1st, 2006 5:15 AM |
| template question | ling_wong | C++ | 1 | Feb 1st, 2006 5:23 AM |
| C++ template and namespace question | Soulstorm | C++ | 3 | Jan 22nd, 2006 2:46 PM |
| Function Template Question | aznluvsmc | C++ | 6 | Oct 7th, 2005 11:37 PM |