Need help with error C2664
I have a question as to why the two shown func args are different? See comments (yes I am novice)
struct MyFileClass
{
.....other code
void MyFileOut( TCHAR* pS, DWORD pVar)
{
TCHAR PrntStrg1[] = _T("The value of passed ptr->");
.... other code
MyFilePrint(&PrntStrg1, Scratch_PP); //<-this pulls error C2664:
//cannot convert parameter 1 from 'TCHAR (*__w64 )[26]' to 'TCHAR *'
MyFilePrint(PrntStrg1, Scratch_PP); //<-this does not
// doesn't PrntStrg1 and &PrntStrg1 evaluate to the same thing ?
......other code
} // end MyFileOut
int MyFilePrint(TCHAR* pS, DWORD pVar)
{
....other code
} // end MyFilePrint
} // end MyFileClass
Re: Need help with error C2664
The type of PrntStrg1 is TCHAR[] which is (almost) the same as TCHAR*.
The type of PrntStrg1* is TCHAR*[] which is (almost) the same as TCHAR**.
Do you see the difference?
Re: Need help with error C2664
Quote:
Originally Posted by
VictorN
The type of PrntStrg1* is TCHAR*[] which is (almost) the same as TCHAR**.
I wouldn't say they are almost the same, because they are not convertible to each other.
Code:
void foo(char** test);
void bar()
{
char array[] = "test";
foo(&array); // error C2664: 'foo' : cannot convert parameter 1 from 'char (*)[5]' to 'char **'
}
Re: Need help with error C2664
Quote:
Originally Posted by
D_Drmmr
I wouldn't say they are almost the same, because they are not convertible to each other.
Code:
void foo(char** test);
void bar()
{
char array[] = "test";
foo(&array); // error C2664: 'foo' : cannot convert parameter 1 from 'char (*)[5]' to 'char **'
}
Yes, you are right.
I just tried to explain the OP problem as short as possible... So sorry for non-correct explanation! :blush:
Re: Need help with error C2664
Quote:
Originally Posted by
VictorN
The type of PrntStrg1 is TCHAR[] which is (almost) the same as TCHAR*.
The type of PrntStrg1* is TCHAR*[] which is (almost) the same as TCHAR**.
Do you see the difference?
Quote:
Originally Posted by
D_Drmmr
I wouldn't say they are almost the same, because they are not convertible to each other.
Code:
void foo(char** test);
void bar()
{
char array[] = "test";
foo(&array); // error C2664: 'foo' : cannot convert parameter 1 from 'char (*)[5]' to 'char **'
}
Quote:
Originally Posted by
VictorN
Yes, you are right.
I just tried to explain the OP problem as short as possible... So sorry for non-correct explanation! :blush:
Thanks for the explanations. I kinda see what your are taking about. I guess I need to do some experimental evaluations to make it more clear to me. I had always thought an Char array was the same as the address of the first character, and that in essense it was the same as Char ptr. So I guess you are saying that I'm passing the address of the ptr instead of the ptr. Anyhow at least you guys have shown me where I have some learning to do. I thank you much.
Re: Need help with error C2664
Quote:
Originally Posted by
J_W
... So I guess you are saying that I'm passing the address of the ptr instead of the ptr.
Exactly! :thumb:
Re: Need help with error C2664
Quote:
Originally Posted by
J_W
I had always thought an Char array was the same as the address of the first character, and that in essense it was the same as Char ptr.
An array is an array (a contiguous buffer of a certain type), and a pointer is a pointer. They are not the same thing.
What you're confused about is that
1) a pointer can be used syntactically to traverse, retrieve, or set an element within an array
2) When you "pass an array" to a function, the receiving function receives a pointer to the first element of the array. Then item 1) takes effect within the function.
But do not make the mistake that an array is a pointer and a pointer is an array. If you want further proof:
Code:
#include <iostream>
using namespace std;
int main()
{
char x[100];
char* y;
cout << sizeof(x) << endl;
cout << sizeof(y) << endl;
}
What values are printed when I attempt to retrieve the size of each of those types? I can bet they are vastly different.
Regards,
Paul McKenzie
Re: Need help with error C2664
Quote:
Originally Posted by
Paul McKenzie
. . . . .
What you're confused about is that
1) a pointer can be used
syntactically to traverse, retrieve, or set an element within an array
2) When you "pass an array" to a function, the receiving function receives a pointer to the first element of the array. Then item 1) takes effect within the function.
But do not make the mistake that an array is a pointer and a pointer is an array. If you want further proof:
Code:
#include <iostream>
using namespace std;
int main()
{
char x[100];
char* y;
cout << sizeof(x) << endl;
cout << sizeof(y) << endl;
}
Regards, Paul McKenzie
Point understood, thank you. 100 bytes compared to 4.