Compiler does not know, which overload of cb
to chose.
2) Even if it did know, it would not convert from void*
to, say void(*)(int)
, without any explicit conversion.
However, it can deduce it if you give compiler enough information:
void cb(int x) { std::cout <<"print inside integer callback : " << x << "\n" ; } void cb(float x) { std::cout <<"print inside float callback :" << x << "\n" ; } void cb(const std::string& x) { std::cout <<"print inside string callback : " << x << "\n" ; } int main() { void(*CallbackInt)(int); void(*CallbackFloat)(float); void(*CallbackString)(const std::string&); CallbackInt = cb; CallbackInt(5); CallbackFloat = cb; CallbackFloat(6.3); CallbackString = cb; CallbackString("John"); return 0; }
Related Posts:
- Usage and Syntax of std::function
- What is a lambda expression in C++11?
- ld: symbol(s) not found for architecture x86_64 error
- What is the ‘override’ keyword in C++ used for? [duplicate]
- What is a smart pointer and when should I use one?
- Meaning of = delete after function declaration
- C++ std::priority_queue uses the lambda expression
- What exactly is nullptr?
- Difference between `constexpr` and `const`
- Split a string using C++11
- How to create timer events using C++ 11?
- What does T&& (double ampersand) mean in C++11?
- Segmentation fault error 11 C++
- Why doesn’t C++ have a garbage collector?
- Compiling C++11 with g++
- terminate called after throwing an instance of ‘std::invalid_argument’ what(): stoi
- What exactly is std::atomic?
- Issue with std::stol – ‘std::invalid_argument’ what(): stol
- terminate called after throwing an instance of ‘std::out_of_range’
- Cleanest way to copy a constant size array in c++11
- push_back vs emplace_back
- undefined reference to ‘std::cout’
- What is move semantics?
- expression preceding parentheses of apparent call must have (pointer-to-) function type
- C++ error: Undefined symbols for architecture x86_64
- C++ terminate called without an active exception
- Thread pooling in C++11
- Callback functions in C++
- How does std::forward work? [duplicate]
- Difference in make_shared and normal shared_ptr in C++
- Invalid use of non-static member function c++
- What is std::move(), and when should it be used?
- C++: std does not have member “string”
- push_back vs emplace_back
- What’s the syntax for declaring an array of function pointers without using a separate typedef?
- error: use of deleted function
- Call to implicitly deleted copy constructor in LLVM
- cc1plus: error: unrecognized command line option “-std=c++11” with g++
- error C2679: binary ‘<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
- no match for ‘operator<<’ in ‘std::operator
- Warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11?
- Use the auto keyword in C++ STL
- Call to non-static member function without an object argument compiler error
- Does C++11 have C#-style properties?
- term does not evaluate to a function taking 1 arguments
- Iterator Loop vs index loop
- initialize a vector to zeros C++/C++11
- When is it safe to call this-> in constructor and destructor
- How to memset char array with null terminating character?
- How well is Unicode supported in C++11?
- How to automatically convert strongly typed enum into int?
- Why should I use a pointer rather than the object itself?
- too many initializers for ‘int [0]’ c++
- Creating folders in C++
- convert string to size_t
- Compiling C++11 with g++
- ERROR C2039: ‘vector’: is not a member of ‘std’
- Does static constexpr variable inside a function make sense?
- c++ vector bubble sort
- How to use bitmask?
- Differences between unique_ptr and shared_ptr
- What is meant by Resource Acquisition is Initialization (RAII)?
- When to use extern “C” in simple words? [duplicate]
- What does the explicit keyword mean?
- Expression must have class type
- Undefined reference to vtable
- How to get current time and date in C++?
- Class name does not name a type in C++
- Identifier not found error on function call
- Using the fstream getline() function inside a class
- Missing vc_runtimeminimum_x86.msi and installation won’t work
- I’m getting an error “invalid use of incomplete type ‘class map’
- “Error: expression must have a pointer type” when using the “this” keyword
- This declaration has no storage class or type specifier in C++
- How to convert C++ Code to C
- how to convert C# to C++
- What are helper functions in C++?
- How to fix ‘std::logic_error’ what(): basic_string::_M_construct null not valid error?
- C++ String Variable Declaration
- How to fix ‘std::logic_error’ what(): basic_string::_M_construct null not valid error?
- fatal error LNK1169: one or more multiply defined symbols found in game programming
- How to initialize a vector of pointers
- C++: Using ifstream with getline();
- How to add element to C++ array?
- Win32 Console Application
- What does the fpermissive flag do?
- Convert char array to single int?
- https://stackoverflow.com/questions/3865946/error-generic-array-creation
- How to print a string in C++
- C++ Void Function with File Stream Error
- ‘setprecision’ is not a member of ‘std’
- How to use stringstream to separate comma separated strings [duplicate]
- When/why to make function private in class?
- Using cin to input a single letter into a char
- C++ calling base class constructors
- Why am I getting an ‘Else without previous if’ error within a for loop?
- Dynamic and static Scoping program differences
- How to fix the error “Windows SDK version 8.1” was not found?
- How to solve “Unresolved inclusion:
” in a C++ file in Eclipse CDT? - How do you clear a stringstream variable?