Redian新闻
>
a simple question for C++ class
avatar
a simple question for C++ class# Programming - 葵花宝典
v*i
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 <return 1;
}
/****************************
para.h
*******************
avatar
o*o
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()

avatar
Q*g
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<}
int main(){
char *a[20] = {"abc","def","ghik"};
cout<f(a);
return 0;
}
avatar
v*i
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<: }
: int main(){
: char *a[20] = {"abc","def","ghik"};

avatar
v*i
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<: }
: int main(){
: char *a[20] = {"abc","def","ghik"};

avatar
c*e
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!
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。