由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - function declaration
相关主题
不用头文件,如何调用函数?C++问个简单问题
C++ namespace 弱问namespace 问题
c++ iterator 弱问C++ template function type
[合集] 关于template和inheritance的问题请教C++ class cross reference problem
Why should i include .cpp instead of .hWhat happens when recursion functions are declared inline?
[合集] 怎样有效的传递C静态数组的变量名?pointer to function
C++默认的copy constructor的疑惑c++ does not check const for extern variable?
一个关于C++ template和overload的问题two c++ interview questions! (转载)
相关话题的讨论汇总
话题: function话题: part话题: extern话题: constness话题: other
进入Programming版参与讨论
1 (共1页)
l*********s
发帖数: 5409
1
Two entry level questions,
1) to declare extern functions, does the compiler differentiate between
"const" and non-const versions? In other words, is constness of /return value and/or arguments part of the function signature?
2) Say, in one source file defined a function ff(str& a),, then in the other
file the function is referenced/declared, however, these two files use
different namespaces, both have defined the symbol str. What will happen?
r*******y
发帖数: 1081
2
just try compiling your program.
extern int f();
extern int f();
is OK using g++
but
extern int f();
extern const int f();
is not OK using g++

value and/or arguments part of the function signature?
other

【在 l*********s 的大作中提到】
: Two entry level questions,
: 1) to declare extern functions, does the compiler differentiate between
: "const" and non-const versions? In other words, is constness of /return value and/or arguments part of the function signature?
: 2) Say, in one source file defined a function ff(str& a),, then in the other
: file the function is referenced/declared, however, these two files use
: different namespaces, both have defined the symbol str. What will happen?

t****t
发帖数: 6806
3
1. in c++, return type is a part of function signature. constness is a part
of type. however you can not overload 2 function with only different return
type, whether it is constness difference or other difference.
2. namespace is a part of name. if two "same" symbol are declared in
different namespace, they are different. however you can refer to symbols in
other namespace, where name lookup algorithm kicks in.

value and/or arguments part of the function signature?
other

【在 l*********s 的大作中提到】
: Two entry level questions,
: 1) to declare extern functions, does the compiler differentiate between
: "const" and non-const versions? In other words, is constness of /return value and/or arguments part of the function signature?
: 2) Say, in one source file defined a function ff(str& a),, then in the other
: file the function is referenced/declared, however, these two files use
: different namespaces, both have defined the symbol str. What will happen?

l*********s
发帖数: 5409
4
Many thanks!

【在 r*******y 的大作中提到】
: just try compiling your program.
: extern int f();
: extern int f();
: is OK using g++
: but
: extern int f();
: extern const int f();
: is not OK using g++
:
: value and/or arguments part of the function signature?

l*********s
发帖数: 5409
5
Cong! You are so knowledgeable!

part
return
in

【在 t****t 的大作中提到】
: 1. in c++, return type is a part of function signature. constness is a part
: of type. however you can not overload 2 function with only different return
: type, whether it is constness difference or other difference.
: 2. namespace is a part of name. if two "same" symbol are declared in
: different namespace, they are different. however you can refer to symbols in
: other namespace, where name lookup algorithm kicks in.
:
: value and/or arguments part of the function signature?
: other

1 (共1页)
进入Programming版参与讨论
相关主题
two c++ interview questions! (转载)Why should i include .cpp instead of .h
c++环境入门问题[合集] 怎样有效的传递C静态数组的变量名?
关于 VC++ vitual, reload 和 derive的一个问题...C++默认的copy constructor的疑惑
[合集] (c++)为什么不能把这个function的definition放到class里一个关于C++ template和overload的问题
不用头文件,如何调用函数?C++问个简单问题
C++ namespace 弱问namespace 问题
c++ iterator 弱问C++ template function type
[合集] 关于template和inheritance的问题请教C++ class cross reference problem
相关话题的讨论汇总
话题: function话题: part话题: extern话题: constness话题: other