Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8257349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:10:22+00:00 2026-06-08T02:10:22+00:00

void f(string str,int i ) { cout<<str.c_str()<<endl; cout<<i<<endl; } typedef void (*PF)(int i,string str);

  • 0
void f(string str,int i )
{
  cout<<str.c_str()<<endl;
  cout<<i<<endl;
}

typedef void (*PF)(int i,string str);


int _tmain(int argc, _TCHAR* argv[])
{

   PF pf=(PF)(void*)&f;

   pf(10,string()); //runtime-error

   return 0;

}

Due to some needs, I need to call the function f using the address of f which data type has been erased (such as the code above). But this solution may cause the insecure function call because the data type can’t be checked during the compiling.
Is there some ways to let the compiler to report an error when the the type of parameters are different from arguments’?

Something like this:

void f(T1 i,T2 j)
{
  T1 p* = new i.real_type; //if i.real_type is different from T1, it will lead a compiling 
....
}

I appreciate that very much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:10:23+00:00Added an answer on June 8, 2026 at 2:10 am

    The only run-time type information available in C++ is typeid and dynamic_cast, and they only work on polymorphic types (class types with virtual functions). Function pointers don’t store the necessary information.

    Really, you should just avoid casting function pointers. The only place a function pointer case is ever necessary is on the return value from GetProcAddress or dlsym.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hopefully whoever reads this knows about default arguments: void setCase (string &str, int form
void getBookData(bookType books[], int& noOfBooks) { ifstream infile; string file = bookData.txt; infile.open(file.c_str()); if
static void Main() { string str; str = Console.ReadLine(); while (str != null)//HERE! {
in java we can do this: public class A{ public static void main(String...str){ B
Far as best practices are concerned, which is better: public void SomeMethod(string str) {
void BinaryTree::InitializeFromFile(string Filename){ ifstream inFile; treenode* Freq[256]; inFile.open(Filename.c_str(), fstream::binary); if(inFile.fail()){ cout<<Error in opening file
I have this function declaration and definition.. definition void loadFromFile( string const& fileName, Frames&
#include <thread> #include <cassert> #include <iostream> #include <string> #include <future> #include <utility> void ThFun(std::promise<std::string>&&
private: System::Void btn_entrar_Click(System::Object^ sender, System::EventArgs^ e) { string btn_texto = txt_login->Text->ToString(); MessageBox(NULL, Hello!, btn_texto.c_str(),
I wrote following function void validateUser(void) { string uName; string uPassword; char c; map

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.