v*******i 发帖数: 19 | 1 I had a puzzling bug today. Though I finally fixed it, I am not clear about
the reason. I describe this question with 3 short codes: example.cpp, para.h
and para.cpp.
/****************************
example.cpp; a "hello world" main function
****************************/
#include
#include "para.h"
using namespace std;
int main()
{
Para example; // example is an instance of class Para.
cout <<"hello world"<
return 1;
}
/****************************
para.h
******************* | o**o 发帖数: 3964 | 2
标 题: Re:没主题
发信站: BBS 未名空间站 (Sun Aug 20 23:52:43 2006)
来 源: 128.174.
呵呵,大家爽快。
哎呀,偶尔谁都会犯错。对了问你一个信息,你的油卡在哪里买的啊。我知道有些gc的
program总觉得特别复杂,不知道怎么弄。
的
【在 v*******i 的大作中提到】 : I had a puzzling bug today. Though I finally fixed it, I am not clear about : the reason. I describe this question with 3 short codes: example.cpp, para.h : and para.cpp. : /**************************** : example.cpp; a "hello world" main function : ****************************/ : #include : #include "para.h" : using namespace std; : int main()
| Q**g 发帖数: 183 | 3 whenever you pass an array as an argument to a function call, it is actually
treated as a pointer. The size information is lost to the function.
try this simple one:
#include
using namespace std;
void f(char *array[]){
cout<<"in function, sizeof(array)="<
}
int main(){
char *a[20] = {"abc","def","ghik"};
cout<<"in main, sizeof(a)="<
f(a);
return 0;
} | v*******i 发帖数: 19 | 4 yeah, you are right. Thanks!
【在 Q**g 的大作中提到】 : whenever you pass an array as an argument to a function call, it is actually : treated as a pointer. The size information is lost to the function. : try this simple one: : #include : using namespace std; : void f(char *array[]){ : cout<<"in function, sizeof(array)="<: } : int main(){ : char *a[20] = {"abc","def","ghik"};
| v*******i 发帖数: 19 | 5 yeah, you are right. Thanks!
【在 Q**g 的大作中提到】 : whenever you pass an array as an argument to a function call, it is actually : treated as a pointer. The size information is lost to the function. : try this simple one: : #include : using namespace std; : void f(char *array[]){ : cout<<"in function, sizeof(array)="<: } : int main(){ : char *a[20] = {"abc","def","ghik"};
| c********e 发帖数: 383 | 6 there is an exception though. If an array is passed as a reference it is
little
bit more than just a bare pointer. size info is also passed.
for example
template
int getsz (T (&a)[size]) { return size;}
HTH
【在 v*******i 的大作中提到】 : yeah, you are right. Thanks!
|
|