-
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.
-
What's the code causing the problem? Why do you need the const?
-
Hrmm
Hey, Parksie, could you please have alook at the thread I posted yesterday "Parallel Port-Urgent" please, thanks in advance :):)
-
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.:confused: