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
|
|