This is a short example of the code I want to use:
template <class T>
class B
{
public :
bool func1(const T& t)
{
// do something
}
};
class A
{
B<int*> b;
public:
void func2(const int* a)
{
b.func1(a);
}
};
I'm getting this error :
error C2664: 'B::func1' : cannot convert parameter 1 from 'const int *' to 'int *const &'
is a way to solve this without changing the functions declarations and without using const_cast?
Edit:
some information behind the problem
B is actually a container class I wrote (lets say a list)
A is a class using that list
func1 is a function that need to find if an element is in the list or not
func2 is a function that recieves an element to remove from the list
When int* is used to instantiate B, the function
void func1(const T& t) {}
is equivalent to:
void func1(int* const& t) {}
A parameter of type const int* is not compatible with int* const&.
You need to rethink your functions a bit.
Update
Use of B<int> instead of B<int*> in A might be what you are looking for.
class A
{
B<int> b;
public:
void func2(const int* a)
{
b.func1(*a);
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With