I wrote a class Min-Max Heap Template Class which works perfectly fine with integers. As part of this data structure, i have to implement some sort of method to check for the smallest children/grandchildren of any given position in the Min-Max Heap array. Part of this method retrieves an item from my MinMaxHeap array at a specific position and then compare it to NULL. This works fine with integers. However i cannot(!) compare strings to NULL. I receive 100+ errors among the following lines: - Error 1 error C2784: 'bool std::operator ==(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const _Elem *' from 'int' c:\documents and settings\dbm\my documents\visual studio 2005\projects\minmaxheap\minmaxheap\minmaxheap.cpp 261
Now, the compiler does this check at compile-time. Not at run-time. So checking if a template is a string or an integer is out of the question. Can i use anything else to fix this problem???
Here is my Function -
template <class Type>
-
const int MinMaxHeap<Type>::findMinChild(const int pos)
-
{
-
/* Get left and right children of current position */
-
int lChildPos = getLChild(pos);
-
int rChildPos = getRChild(pos);
-
-
/* Get items at left and right positions */
-
Type itemAtLeft = getElementAtPos(lChildPos);
-
Type itemAtRight = getElementAtPos(rChildPos);
-
-
if (typeid(itemAtLeft) == typeid(string))
-
{
-
if (itemAtLeft.size() == 0 || itemAtRight.size() == 0 || itemAtLeft < itemAtRight)
-
return lChildPos;
-
return rChildPos;
-
}
-
else
-
{
-
/* Compare both children and return the smallest */
-
compCount++;
-
if (itemAtLeft == NULL || itemAtRight == NULL || itemAtLeft < itemAtRight)
-
return lChildPos;
-
return rChildPos;
-
}
-
}
-
As you can see i am attempting to check the template argument for strings, which of course doesn't work. So i am looking for some sort of other way to check both strings and integers for null :(
Any help is appreciated!
6 2253 Savage 1,764
Recognized Expert Top Contributor
I wrote a class Min-Max Heap Template Class which works perfectly fine with integers. As part of this data structure, i have to implement some sort of method to check for the smallest children/grandchildren of any given position in the Min-Max Heap array. Part of this method retrieves an item from my MinMaxHeap array at a specific position and then compare it to NULL. This works fine with integers. However i cannot(!) compare strings to NULL. I receive 100+ errors among the following lines: - Error 1 error C2784: 'bool std::operator ==(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const _Elem *' from 'int' c:\documents and settings\dbm\my documents\visual studio 2005\projects\minmaxheap\minmaxheap\minmaxheap.cpp 261
Now, the compiler does this check at compile-time. Not at run-time. So checking if a template is a string or an integer is out of the question. Can i use anything else to fix this problem???
Here is my Function -
template <class Type>
-
const int MinMaxHeap<Type>::findMinChild(const int pos)
-
{
-
/* Get left and right children of current position */
-
int lChildPos = getLChild(pos);
-
int rChildPos = getRChild(pos);
-
-
/* Get items at left and right positions */
-
Type itemAtLeft = getElementAtPos(lChildPos);
-
Type itemAtRight = getElementAtPos(rChildPos);
-
-
if (typeid(itemAtLeft) == typeid(string))
-
{
-
if (itemAtLeft.size() == 0 || itemAtRight.size() == 0 || itemAtLeft < itemAtRight)
-
return lChildPos;
-
return rChildPos;
-
}
-
else
-
{
-
/* Compare both children and return the smallest */
-
compCount++;
-
if (itemAtLeft == NULL || itemAtRight == NULL || itemAtLeft < itemAtRight)
-
return lChildPos;
-
return rChildPos;
-
}
-
}
-
As you can see i am attempting to check the template argument for strings, which of course doesn't work. So i am looking for some sort of other way to check both strings and integers for null :(
Any help is appreciated!
- could not deduce template argument for 'const _Elem *' from 'int'
.
Have you tryed using 'int*'?
Savage
I honestly don't understand what '_const Elem*' even means. I'm not passing any template argument pointers, neither do any of my functions return any. Apparently this problem has nothing to do with comparing strings to NULL. After doing some research, i found out that for some reason the compiler cannot determine the Type of a function so you have to pass it explicitly Like:
foo<Type>(param1, param2), which in turn says something like "Illegal use of Type" or something similar to that. Either way, it doesn't work.
This is really bugging me out. I have never seen this problem before.
When you ask if i tried 'int*' where in the code should i try this?
Thank you.
Savage 1,764
Recognized Expert Top Contributor
I honestly don't understand what '_const Elem*' even means. I'm not passing any template argument pointers, neither do any of my functions return any. Apparently this problem has nothing to do with comparing strings to NULL. After doing some research, i found out that for some reason the compiler cannot determine the Type of a function so you have to pass it explicitly Like:
foo<Type>(param1, param2), which in turn says something like "Illegal use of Type" or something similar to that. Either way, it doesn't work.
This is really bugging me out. I have never seen this problem before.
When you ask if i tried 'int*' where in the code should i try this?
Thank you.
NULL it self is setting a pointer to point toward null.Int which you use to determine childs is not a pointer ,but int* is one.Strings them selfs are array of chars where it's
name point to location.So setting and comparing string with NULL should not
make a problem.This - could not deduce template argument for 'const _Elem *' from 'int'
is probably making a problem because it's of const
type and such as it is it's not allowing any change of his value and make a compile prob when compiling.
One of solution might be,as you said,explicit but right now I don't know why is
it reporting invalid use of type??
Savage
Not a single clue. I've tried pretty much everything i could. The only thing left is to actually overload the equality operator (==), since that's where it seems to fail. I still don't fully understand what the heck's causing this and why the template args aren't passed. It's almost as if strings don't have == defined lol. Which is just bogus.
Ok i guess i can call this *RESOLVED*. The problem was not the == operator, it was comparing strings to NULL which returns the whole shibang of error messages. So i'm just comparing template args to string and compare it to "" if it's a string.
Thanks for the help.
Savage 1,764
Recognized Expert Top Contributor
Ok i guess i can call this *RESOLVED*. The problem was not the == operator, it was comparing strings to NULL which returns the whole shibang of error messages. So i'm just comparing template args to string and compare it to "" if it's a string.
Thanks for the help.
I wasn't much of help,but im glad it's *RESOLVED* !!!!
Savage
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Kaneda |
last post by:
Hello everyone!
I have some weird(?) problems, and I am not quite sure if there are due to
my errors or maybe a limitation in the .Net framework.
I have a ComboBox I need to fill with the...
|
by: Kaneda |
last post by:
Hello everyone!
I have some weird(?) problems, and I am not quite sure if there are due to
my errors or maybe a limitation in the .Net framework.
I have a ComboBox I need to fill with the...
|
by: Holger (David) Wagner |
last post by:
Hi all,
we're currently developing an application in the .NET environment that
needs to access a DLL implemented in Fortran. There is one procedure
with about 17 parameters, most of them arrays....
|
by: ZorpiedoMan |
last post by:
This is so weird, and I cannot even isolate the cause enough to give any
clues as to how to reproduce the error, so this is probably a real shot
in the dark...
BUT, has anyone ever run into a...
|
by: kvu95111 |
last post by:
Hi All,
I have wrote a simple program using RS232 protocol. However, I have the following problem in hand.
I used the software to receive data from a RFID reader (you may simply treat it like a...
| |
by: WStoreyII |
last post by:
the following code is supposed to read a whole line upto a new line
char from a file. however it does not work. it is producing weird
results. please help. I had error checking in there for...
|
by: P Pulkkinen |
last post by:
Dear all,
sorry, i know this code is far little too long to debug here, but there is
really annoying logical error. If someone debugs this, I really offer warm
virtual handshake.
What this...
|
by: Radu |
last post by:
As simple-to-remember-but-unique confirmation numbers, I need to
generate six random characters (ASCII 65 to 90, inclusive):
Randomize()
objStringBuilder.Append(Chr(CInt(Int((25 * Rnd()) +...
|
by: =?Utf-8?B?amVmZmVyeQ==?= |
last post by:
i need help with a combo box and this same code works on my first tab with a
combo box. The error or problem i have is this code causes an index out of
range error when i run it on my second combo...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |