|
-
Apr 6th, 2001, 04:42 PM
#1
Thread Starter
Addicted Member
Hello,
I have a class called "Set<T>" (a template class) and a function outside of it. One of the parameters of the function is "const Set<T> &setCompare2".
Inside the function, I need to call one of the (public)member functions of the class called "IsMember" (from the setCompare2 variable).
The problem is that when I compile the program, I get this error:
"error C2662: 'IsMember' : cannot convert 'this' pointer from 'const class Set<int>' to 'class Set<int> &'"
Currently, I have 3 solutions to this problem that may work, but every solution has its flaw:
1. Changing the function parameter from "const Set<T> &setCompare2" to "Set<T> &setCompare2". I can't do that because of the instructions of writing this program (it's an exercise).
2. Copying the lines of the IsMember function to the problematic function: not efficient.
3. Declaring a "Set<T>" local variable in the problematic function, copying all the setCompare2's attributes values into it and using it to call the IsMember function:
requires a lot of time from the processor (many copy instructions).
Does anyone have another idea?
Thanks.
-
Apr 6th, 2001, 04:48 PM
#2
Monday Morning Lunatic
What's the code causing the problem? Why do you need the const?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Apr 6th, 2001, 07:14 PM
#3
-
Apr 7th, 2001, 03:24 AM
#4
Thread Starter
Addicted Member
The line causing the problem is:
"if (setCompare2.IsMember(setCompare1.ElementsArray[Counter])==NOT_FOUND)"
(setCompare1 and setCompare2 are declared as "const Set<T>&").
I need to declare setCompare2 as a constant parameter because the function is not supposed to be able to change it. These are the instructions of writing this program, so I can't change the declaration.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|