由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - a simple question for C++ class
相关主题
一个指向指针的指针的引用?腆着脸在问一道
a question about bitwise operation关于C++中一个Class的大小 (转载)
C++里get array size的问题 (转载)问个简单的memory allocation 的问题。
C++ Q04: template member用数组做参数,在函数内部如何知道数组的size?
私有成员不能用类成员函数修改?请大侠评点一下我这个C++多重继承的程序。。。写得对不对啊。
一个关于C++ template和overload的问题我这个C++程序有没有什么问题啊?请指点。。。谢谢。。。
数组定义的时候,分配空间了么?请教个static_cast vs reinterpret_cast的问题。
C++小程序查错c++ question
相关话题的讨论汇总
话题: para话题: main话题: c++话题: question话题: include
进入Programming版参与讨论
1 (共1页)
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!
1 (共1页)
进入Programming版参与讨论
相关主题
c++ question私有成员不能用类成员函数修改?
One c++ non-type template question一个关于C++ template和overload的问题
来,出个题数组定义的时候,分配空间了么?
一个古怪的C程序运行错误。C++小程序查错
一个指向指针的指针的引用?腆着脸在问一道
a question about bitwise operation关于C++中一个Class的大小 (转载)
C++里get array size的问题 (转载)问个简单的memory allocation 的问题。
C++ Q04: template member用数组做参数,在函数内部如何知道数组的size?
相关话题的讨论汇总
话题: para话题: main话题: c++话题: question话题: include