Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 4th, 2007, 12:38 PM   #1
rsnd
Hobbyist Programmer
 
rsnd's Avatar
 
Join Date: Jun 2005
Location: Helltown
Posts: 162
Rep Power: 4 rsnd is on a distinguished road
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!
rsnd is offline   Reply With Quote
Old Jul 4th, 2007, 12:41 PM   #2
pegasus001
Hobbyist Programmer
 
pegasus001's Avatar
 
Join Date: Nov 2006
Location: 163H
Posts: 213
Rep Power: 2 pegasus001 is on a distinguished road
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.
pegasus001 is offline   Reply With Quote
Old Jul 4th, 2007, 12:47 PM   #3
rsnd
Hobbyist Programmer
 
rsnd's Avatar
 
Join Date: Jun 2005
Location: Helltown
Posts: 162
Rep Power: 4 rsnd is on a distinguished road
umm ok...what was the problem?
__________________
Spread your wings and fly! Chicken!
rsnd is offline   Reply With Quote
Old Jul 4th, 2007, 12:48 PM   #4
pegasus001
Hobbyist Programmer
 
pegasus001's Avatar
 
Join Date: Nov 2006
Location: 163H
Posts: 213
Rep Power: 2 pegasus001 is on a distinguished road
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.
pegasus001 is offline   Reply With Quote
Old Jul 4th, 2007, 1:05 PM   #5
rsnd
Hobbyist Programmer
 
rsnd's Avatar
 
Join Date: Jun 2005
Location: Helltown
Posts: 162
Rep Power: 4 rsnd is on a distinguished road
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:
H:\test.cpp:12: error: could not convert template argument `0' to `char*'
H:\test.cpp:12: error: invalid type in declaration before ';' token
seems like some sort of type casting failure but isnot 0 a valid value for a pointer?
__________________
Spread your wings and fly! Chicken!
rsnd is offline   Reply With Quote
Old Jul 4th, 2007, 1:34 PM   #6
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 261
Rep Power: 4 Cache is on a distinguished road
I think pointer template arguments have to have external linkage. Presumably '0' doesn't. You'll have to do some digging.
Cache is offline   Reply With Quote
Old Jul 4th, 2007, 1:48 PM   #7
rsnd
Hobbyist Programmer
 
rsnd's Avatar
 
Join Date: Jun 2005
Location: Helltown
Posts: 162
Rep Power: 4 rsnd is on a distinguished road
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!
rsnd is offline   Reply With Quote
Old Jul 4th, 2007, 5:42 PM   #8
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 825
Rep Power: 4 The Dark is on a distinguished road
You could try using a cast to _Type around the 0 in the initialiser.
The Dark is offline   Reply With Quote
Old Jul 4th, 2007, 6:18 PM   #9
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 261
Rep Power: 4 Cache is on a distinguished road
Quote:
Originally Posted by The Dark View Post
You could try using a cast to _Type around the 0 in the initialiser.
It still wouldn't have external linkage.
Cache is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:35 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC