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

  • Home
  • SEARCH
  • 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 6019823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:28:37+00:00 2026-05-23T03:28:37+00:00

I wrote the following piece of code on codepad but I do not understand

  • 0

I wrote the following piece of code on codepad but I do not understand how/why it should compile.

#include<iostream>

using namespace std;

typedef double dObject;
typedef int iObject;
typedef void (*swapfuncptr)(dObject, dObject);

void swap(dObject a,dObject b) {
cout << a << " " << b << endl;
dObject tmp;
tmp = a;
a = b;
b = tmp;
cout << a << " " << b << endl;
}
int main() {

double a = 7.5, b = 5.3;
swapfuncptr swapptr1;
swapptr1 = &swap;
swapptr1(a, b);

int c = 3, d = 2;
swapfuncptr swapptr2;
swapptr2 = &swap;
swapptr2(c, d);

swapfuncptr swapptr3;
swapptr3 = &swap;
swapptr3('r', 'd');
return 0;
}

So dobject is only for doubles for the functions with integer parameters also work. I do not get how this works.

Can someone please explain.

Thanks
S

  • 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-05-23T03:28:38+00:00Added an answer on May 23, 2026 at 3:28 am

    int is implicitly convertable to double. Creating a typedef for double does not change that.

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

Sidebar

Related Questions

Let's look at the following piece of code which I unintentionally wrote: void test
I'm trying to write a piece of code that will do the following: Take
Using an idea from Bob King idea I wrote the following method. It works
In C++Builder, I wrote the following code (in Button1Click handler), When I run in
I needed some simple string encryption, so I wrote the following code (with a
I wrote this piece of code to my bootstrap public function _initRouter() { $pages
I have the following piece of code to write data to an XML file.
I have a piece of code in C with the following: a = b
I found myself writing the following piece of code over and over again: MyModel.find(my_id).my_field
I am using jQuery Validation Plugin (http://bassistance.de/jquery-plugins/jquery-plugin-validation/) I have wrote following rule jQuery.validator.addMethod(valueNotEquals, function(value,

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.