473,493 Members | 4,333 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Really weird strings problem.

59 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. 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
Expand|Select|Wrap|Line Numbers
  1. template <class Type>
  2. const int MinMaxHeap<Type>::findMinChild(const int pos)
  3. {
  4.     /* Get left and right children of current position */
  5.     int lChildPos = getLChild(pos);
  6.     int rChildPos = getRChild(pos);
  7.  
  8.     /* Get items at left and right positions */
  9.     Type itemAtLeft = getElementAtPos(lChildPos);
  10.     Type itemAtRight = getElementAtPos(rChildPos);
  11.  
  12.     if (typeid(itemAtLeft) == typeid(string))
  13.     {
  14.         if (itemAtLeft.size() == 0 || itemAtRight.size() == 0 || itemAtLeft < itemAtRight)
  15.             return lChildPos;
  16.         return rChildPos;
  17.     }
  18.     else
  19.     {
  20.         /* Compare both children and return the smallest */
  21.         compCount++;
  22.         if (itemAtLeft == NULL || itemAtRight == NULL || itemAtLeft < itemAtRight)
  23.             return lChildPos;
  24.         return rChildPos;
  25.     }
  26. }
  27.  
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!
Apr 13 '07 #1
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:
Expand|Select|Wrap|Line Numbers
  1. 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
Expand|Select|Wrap|Line Numbers
  1. template <class Type>
  2. const int MinMaxHeap<Type>::findMinChild(const int pos)
  3. {
  4.     /* Get left and right children of current position */
  5.     int lChildPos = getLChild(pos);
  6.     int rChildPos = getRChild(pos);
  7.  
  8.     /* Get items at left and right positions */
  9.     Type itemAtLeft = getElementAtPos(lChildPos);
  10.     Type itemAtRight = getElementAtPos(rChildPos);
  11.  
  12.     if (typeid(itemAtLeft) == typeid(string))
  13.     {
  14.         if (itemAtLeft.size() == 0 || itemAtRight.size() == 0 || itemAtLeft < itemAtRight)
  15.             return lChildPos;
  16.         return rChildPos;
  17.     }
  18.     else
  19.     {
  20.         /* Compare both children and return the smallest */
  21.         compCount++;
  22.         if (itemAtLeft == NULL || itemAtRight == NULL || itemAtLeft < itemAtRight)
  23.             return lChildPos;
  24.         return rChildPos;
  25.     }
  26. }
  27.  
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!
Expand|Select|Wrap|Line Numbers
  1. could not deduce template argument for 'const _Elem *' from 'int'
.

Have you tryed using 'int*'?


Savage
Apr 13 '07 #2
gasfusion
59 New Member
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.
Apr 13 '07 #3
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
Expand|Select|Wrap|Line Numbers
  1. 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
Apr 13 '07 #4
gasfusion
59 New Member
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.
Apr 13 '07 #5
gasfusion
59 New Member
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.
Apr 13 '07 #6
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
Apr 13 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2073
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...
0
1142
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...
3
5811
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....
9
1271
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...
0
1649
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...
14
2700
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...
0
1809
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...
1
1777
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()) +...
6
1859
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...
0
7118
marktang
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,...
0
6980
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...
0
7157
Oralloy
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,...
0
7192
jinu1996
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...
1
6862
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...
1
4886
isladogs
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...
0
4579
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...
0
3087
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...
0
282
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.