The following code fails to compile with two errors on the line 'func(&pobj);' stating "Cannot convert 'X * *' to 'const X * *' in function main()" and "Type mismatch in parameter 1 (wanted 'const X * *', got 'X * *') in function main()" even though its the correct way to pass pointer parameters. And also on commenting this particular line i.e 'func(&pobj);' and uncommenting the two lines above it which declares a new 'const' pointer 'pp' of required type (in parameter of func) but still throws an error on the line which declares and assigns 'pp' saying "Cannot convert 'X * *' to 'const X * *' in function main()".
using X = int;
void func(const X **);
int main() {
X *pobj = new X(58);
// const X **pp = &pobj; // ERROR
// func(pp);
func(&pobj); // ERROR
}
I believe that this is the correct way to pass constant pointers as parameters and I just don't understand why the program fails to compile. Can anyone point out the fault in the code above and suggest me the correct logic/syntax if I am wrong? Thanks in advance.
UPDATE: This question was marked as duplicate but it doesn't have the answer that solves the problem at hand. Thus I would love it if the Stack Overflow community would help me to solve my problem here. Thanks.