|
Thankyou that worked, but now having problems with the pData pointer. I thought it would be easy to use seperate files. Rather than messing about I have placed the whole thing in the single header file, it's only a small class.
|
|
|
|
|
template classes inmplementations have to be in the header...
what is the problem with pData exactly ?
|
|
|
|
|
I can't remember eaxactly after putting it back in the header, it was something about an unknown class size when trying to delete it. Basicaly this is just a template similar to the vector class, with the exception it's smaller and calls the destructor.
|
|
|
|
|
toxcct wrote: template classes inmplementations have to be in the header.
This is only because there is no compiler out there that meets this part of the standard (mainly due to the insane complexity it takes to accomplish it). The standard allows for placing template definitions in header files and implementations in cpp files.
To get around this problem, I generally either put the entire class definition and implementation into a single file, or I place a #include "myclass.cpp" at the bottom of my header file.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
yes i know that, but that fact is that actually, so i didn't want to pollute the post with something that wouldn't have helped...
|
|
|
|
|
Probably problem is you have used TCollection class object without using argument list.
You need to use it like this,
TCollection<int> objTCollection;
|
|
|
|
|
waldermort wrote: I have defined a template class in a header file like so:
It's a class template, not a template class.
waldermort wrote: Then try to declare the members in the cpp file like so:
You cannot define template members in a cpp file. Look up the C++ FAQ!
|
|
|
|
|
Well I do appologise if my English offends you, although it appears the other members (forum members that is and not class members before you get confused) here did not have such a hard time understanding me. May I ask, Mr.Anonymuos, do you use the same attitude when your customers come to you with a problem?
|
|
|
|
|
When defining you must explicitly declare the function as template:
<br />
template <class _T> TCollection<_T>::TCollection () : pData(0), pCount(0)<br />
{<br />
}<br />
template <class _T> TCollection<_T>::~TCollection ()<br />
{<br />
clear();<br />
}<br />
----------------------
Mayank Thakore
Learning C++ - since 1998
They didn't print my card right; so I resigned.
|
|
|
|
|
well, you're right.
indeed, i think i already answered him (if you read the previous posts...)
|
|
|
|
|
Separating template classes into .h and .cpp files is too much of a headache when you're just starting out with templates. It's far easier to put everything in the .h file. See the C++ FAQ Lite[^] template section for more details.
|
|
|
|
|
Hi!
I have a question about dynamically allocated memory, actually about cleaning that memory.
For example I compile and run this piece of code:
char *pString = NULL;
if ( (pString = new char [100]) == NULL )
exit( EXIT_FAILURE );
... <--- Use pString
delete [] pString;
The question is how does the program know how much memory (how many bytes) to free (deallocate)? Isn't it compulsory to specify the number of bytes between the two brackets in order to be sure that it will free all the dynamically allocated memory?
Any suggestions would be greatly appreciated!
Thanks in advance!
|
|
|
|
|
Each heap allocation keeps track of its size.
Steve
|
|
|
|
|
|
|
Did you read his question ??
The link you posted has nothing to do with new and delete, it is purely C programming (alloc, malloc, realloc, ...).
When posting a link, at least take the time to verify if it contains valuable information for the OP.
Just googling and pasting the first link that cames up is not really helpfull.
|
|
|
|
|
It seems I must read complete a thread not only title,thanks for remind,sometime when I see a title I guess body is like title (thanks), but i dont think that stuff and paste link is good,yes?
|
|
|
|
|
WhiteSky wrote: It seems I must read complete a thread not only title
Of course !! That seems logical no ? How can you describe completely a problem in one single title line ??
WhiteSky wrote: but i dont think that stuff and paste link is good
It depends. Sometimes it is usefull, but sometimes it can be really annoying. For example if that links to a lot of text and if the OP needs to search a lot to find the information, it is in general not very valuable. And if you provide a link to something you googled for, then at least verify that it contains the information.
We ask the people who post the questions to have some respect for the other (so formulate the questions correctly, use proper english if possible, ...) but the opposite is true also.
|
|
|
|
|
Cedric Moonen wrote: Of course !! That seems logical no ? How can you describe completely a problem in one single title line ??
"How to show a bmp file on background of dialog"
a title i think see yesterday not sure well
anyway when you see this sentence what do you think?so its possible of course not always.
--------------------------
...but sometime Im wondering because you see a question and sender explain a lot of then you search and find a site when you answer to sender he say its very helpful,great and... but i want to know why sender doesnt search or sometime some one ask what is ?(it) without any try
|
|
|
|
|
I am on a console application that supports MFC. In turbo C under dos, we can use the clrscr(); command to clear the screen. Is there any equivalent which I can use in my case (console app that supports MFC)?
Thanks
Brahmma
You have an apple and me too. We exchange those and We have an apple each.
You have an idea and me too. We exchange those and We have two ideas each.
|
|
|
|
|
brahmma wrote: command to clear the screen
Try this:
system("cls");
I hope this helps...
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
using system() is bad. windows provides an API for consoles, but i don't remember its name...
|
|
|
|
|
Thanks for making me recall that. It was just a quick suggestion.
See Here for some information on Console's
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
I need to display Greek and English in two different CEdit controls on a dialog. How can I do this?
|
|
|
|
|
LeathurBoy wrote: need to display Greek and English in two different CEdit controls on a dialog. How can I do this?
enable UNICODE in your program
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|