由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Any better way to declare a function?
相关主题
Google Java coding standard (转载)C++ Template Question
请教cosnt的使用recursive template?
[合集] 为什么不能: declare a static memeber func问个基本 C array 问题
pointer to functionWhat is the difference between class and struct?
这个function pointer最后的那个int是什么意思?forward declaration
一道面试怪题C++. (转载)C++ memcpy declaration use restrict keyword?
typedefconst reference in copy constructor
class D:public B;C++ class cross reference problem
相关话题的讨论汇总
话题: any话题: func话题: declare话题: way话题: constant
进入Programming版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
I am declaring a function with a char pointer as input, or no input
int func(char *in="new");
Is it the right way to do it? Any better way to do it? Thanks.
Use CC, I got a warning.
w***y
发帖数: 78
2
"new" is a constant so you'd better declare func as
int func(const char *in = "new");
c**********e
发帖数: 2007
3
But in general, the input is not constant.

【在 w***y 的大作中提到】
: "new" is a constant so you'd better declare func as
: int func(const char *in = "new");

w***y
发帖数: 78
4
If your func modifies the content of the string, then it is incorrect to
provide a constant default parameter.
If your func does not modify the content of the string, then it doesn't hurt
to declare the parameter as constant. Your func will still happily accept a
non-constant char *.
1 (共1页)
进入Programming版参与讨论
相关主题
C++ class cross reference problem这个function pointer最后的那个int是什么意思?
Question on C++ Access Control (protected)一道面试怪题C++. (转载)
new and delete in c++typedef
为什么我的visual C++ 找不到 "Stdafx.h" ?class D:public B;
Google Java coding standard (转载)C++ Template Question
请教cosnt的使用recursive template?
[合集] 为什么不能: declare a static memeber func问个基本 C array 问题
pointer to functionWhat is the difference between class and struct?
相关话题的讨论汇总
话题: any话题: func话题: declare话题: way话题: constant