Jun 18, 2009 at 1:17pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14
bool __stdcall check_expiry_date_file(wstring filename,bool cutrun);
int std__call happy()
{
check_expiry_date_file ( filename, &cutrun); // warning C4305: 'argument' : truncation from 'bool *' to 'bool'
//warning C4800: 'bool *' : forcing value to bool 'true' or 'false' (performance warning)
}
bool check_expiry_date_file(wstring filename,bool cutrun)
{
return (false );
}
compile warning,
what's wrong , thanks
Last edited on Jun 18, 2009 at 1:22pm UTC
Jun 18, 2009 at 1:36pm UTC
I'm assuming cutrun
is a bool.
check_expiry_date_file takes a bool as a parameter. If cutrun is a bool, then you'd pass it with just cutrun
, not with &cutrun
. &cutrun
gives you a pointer to a bool.
Jun 18, 2009 at 1:53pm UTC
hi , Dusch
because i need to pass value back to happy(), so i use &, if don't use & , then it can not achieve what i want them to do ~~
hope i haven't misunderstand your meaning~ ~
Last edited on Jun 18, 2009 at 2:16pm UTC
Jun 18, 2009 at 2:20pm UTC
If you want your check_expiry_date_file function to change 'cutrun' in the calling fuction (in this case, happy), you need to pass it by reference or by pointer. Currently you are passing by value which does not do what you want.
Here's an example of your options:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
void ByVal(int v)
{
v = 1;
}
void ByRef(int & v)
{
v = 2;
}
void ByPtr(int * v)
{
*v = 3;
}
void TestFunction()
{
int test = 0;
ByVal(test);
cout << test; // outputs '0' (test not changed because it was passed by value)
ByRef(test);
cout << test; // outputs '2' (test changed)
ByPtr(&test);
cout << test; // outputs '3' (test changed)
}
Therefore you probably want to change check_expiry_date_file so that it passes cutrun by reference or by pointer, not by value.
EDIT: stupid typos
Last edited on Jun 18, 2009 at 2:22pm UTC
Jun 18, 2009 at 2:50pm UTC
OH , thanks for Disch
that means i need to add a * in front of cutrun at called function~ ~ --> no warning now
but i want to ask
do i need to do it (add * in front of parameter of function which haven't & )
everytime when i use pass by reference~ ~
don't the default is pass by Value ? (that means * already)
i don't understand why & at caller, the value will not be show in it?
i already use pass by reference
Last edited on Jun 18, 2009 at 3:19pm UTC
Jun 18, 2009 at 3:08pm UTC
I'm afraid I don't quite understand what you are asking.
If you forget a * or & somewhere, the compiler will throw an error or warning, so you'll know if you're doing it wrong.