Alexander Malkis <al************ *****@stone.cs. uni-sb.de> wrote in message news:<c4******* *****@hades.rz. uni-saarland.de>...
//Consider:
class A { /*...*/ };
template<class T> class list {/*... */ };
void f(const list<const A*> lst) { /*...doesn't change the arg...*/ }
void g(list<A*> lst) {
f(lst); //Intuitively ok, but compiler rejects.
}
/* Compiler says:
error: conversion from `list<A*>' to non-scalar type `list<const A*>'
requested
Cast doesn't help either. What to do?
*/
2 things
1) You are working on a list why not use the STL list(or one of the
other containers)?
2) did you really mean -> void f(const list<const A*> lst)
or did you want to do -> void f(const list<const A*>& lst)
?
That said because you are using a template there are two distinct
classes one is list<A*> and the other is list<const A*> which are in
no way related.
My first guess is that you'd need to write a conversion routine that
accepts a T and converts is to a const T.
My first guess seems to be supported by the compiler I'm using (VC++
7)
The intel compiler spits out the following error:
error: no suitable user-defined conversion from "list<A *>" to "const
list<const A *>" exists f(lst); //Intuitively ok, but compiler
rejects.
The M$ compiler spits out the following error:
error C2664: 'f' : cannot convert parameter 1 from 'list<T>' to 'const
list<T>' with [ T=A * ] and [ T=const A * ]