function-signature

c++ function syntax/prototype - data type after brackets

蓝咒 提交于 2020-05-13 01:23:19
问题 I am very familiar with C/C++ standard function declarations. I've recently seen something like this: int myfunction(char parameter) const The above is only a hypothetical example and I don't even know if it makes sense. I'm referring to the part AFTER the parameter. The const. What is this? A more real example: wxGridCellCoordsArray GetSelectedCells() const This can be found here So what exactly is that text const doing at the end of the line? 回答1: The const keyword, when shown after a

c++ function syntax/prototype - data type after brackets

别等时光非礼了梦想. 提交于 2020-05-13 01:20:53
问题 I am very familiar with C/C++ standard function declarations. I've recently seen something like this: int myfunction(char parameter) const The above is only a hypothetical example and I don't even know if it makes sense. I'm referring to the part AFTER the parameter. The const. What is this? A more real example: wxGridCellCoordsArray GetSelectedCells() const This can be found here So what exactly is that text const doing at the end of the line? 回答1: The const keyword, when shown after a

c++ function syntax/prototype - data type after brackets

拥有回忆 提交于 2020-05-13 01:20:52
问题 I am very familiar with C/C++ standard function declarations. I've recently seen something like this: int myfunction(char parameter) const The above is only a hypothetical example and I don't even know if it makes sense. I'm referring to the part AFTER the parameter. The const. What is this? A more real example: wxGridCellCoordsArray GetSelectedCells() const This can be found here So what exactly is that text const doing at the end of the line? 回答1: The const keyword, when shown after a

Check that signature of two functions or member function pointer equal

三世轮回 提交于 2019-12-24 14:03:12
问题 I write some code for check that signature of free function is equal to signature of member function, etc. It compare extracted return type and function arguments: #include <tuple> #include <type_traits> template<class Signature> struct signature_trait; template<class R, class... Args> struct signature_trait<R(Args...)> { using return_type = R; using arg_types = std::tuple<Args...>; }; template<class R, class... Args> struct signature_trait<R(*)(Args...)> { using return_type = R; using arg

Fill a vector with pointers to partially specialized function members automatically

穿精又带淫゛_ 提交于 2019-12-24 03:52:54
问题 I am working on a pipeline-like design pattern. One of my design goals is to enable dynamic linking of pipeline segments by providing pointers to function members of a certain data class. Each of the data classes has a set of function members (representing the data class output ports) indexed using an integer template argument. These functions deduce the return type dynamically using keyword auto , but all accept the same integer argument c_Idx , i.e. template <int N> auto getOutput(int c_Idx

Function signature of Tap (K-combinator)

前提是你 提交于 2019-12-21 21:43:23
问题 I've read in a book that the function signature of tap function (also called K-Combinator) is below: tap :: (a -> *) -> a -> a "This function takes an input object a and a function that performs some action on a. It runs the given function with the supplied object and then returns the object." Can someone help me to explain what is the meaning of star (*) in the function signature? Are below implementation correct? If all the three implementation are correct, which one should be used when?

Function pointers with default parameters in C++

纵饮孤独 提交于 2019-12-18 18:37:15
问题 How does C++ handle function pointers in relation to functions with defaulted parameters? If I have: void foo(int i, float f = 0.0f); void bar(int i, float f); void (*func_ptr1)(int); void (*func_ptr2)(int, float); void (*func_ptr3)(int, float = 10.0f); Which function pointers can I use in relation to which function? 回答1: Both foo() and bar() can only be assigned to func_ptr2 . §8.3.6/2 : A default argument is not part of the type of a function. [Example: int f(int = 0); void h() { int j = f

why name mangling isn't breaking my program? [duplicate]

心不动则不痛 提交于 2019-12-11 07:59:37
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Is main() overloaded in C++? here's my code: #include <iostream> int main(void* a, void* b) { std::cout << "hello standalone " << std::endl; return 0; } different parameters should have a different symbol name after name mangling( void* a, void* b) should be different from (int, char** ), but this program doesn't have any problem when running. Why is that? 回答1: Because main is a special case, and the compiler

Is it possible to retrieve the argument types from a (Functor member's) function signature for use in a template?

旧时模样 提交于 2019-12-06 05:16:33
问题 Assume you have a functor: struct MyFunctor { bool operator ()( int value ) { return true; } }; Is it possible to retrieve a functor's member's argument type for use within your template? The following is a use of this mythical functionality: template < typename FunctorType > bool doIt( FunctorType functor, typename FunctorType::operator()::arg1 arg ) { return functor( arg ); } Is there a valid syntax that would substitute for my mythical FunctorType::operator()::arg1 ? 回答1: No there is not.

Can an unnamed parameter of function have a default value?

三世轮回 提交于 2019-12-05 18:16:17
问题 Is the following code legal in C++? void f(void* = 0) {} int main() { f(); } Which page of the C++ standard states that this usage is legal? 回答1: Yes, it's legal. There is no standard wording to allow this combination of features specifically; there simply isn't any to disallow it, either. Default argument syntax applies to function parameters in a parameter-declaration : [C++11: 8.3.6/1]: If an initializer-clause is specified in a parameter-declaration this initializer-clause is used as a