Parameter question...

What does this do, and why is this function call wrong?

function: void swapit(int& a, double& b);

with variable

int f;
double g;


??
I can only guess what the function does since you haven't included the code for it.

Based on the name, I would say it swaps the two arguments. Swapping an int and a double will cause truncation of the double. If you are going to swap two values, you usually want to make them the same type.

This is a function somebody wrote. We have no idea what it does. We can guess based on the name that it is a template function that swaps the values of two objects of the same type, and that it fails if you feed it two objects of different types because it only works with objects of the same type, but that's just a guess. it's just some function somebody wrote and it could do anything.


It could do nothing. It could deliberately crash. it could print out the winning score of the 1988 UK FA Cup Final.
Last edited on
Well that is the answer, that it won't work because they are not the same type. There is no code, that was simply the question, even though this was more simple, my teacher has given us extremely poorly instructed labs that make me go what the fuck is the question asking constantly.
closed account (3qX21hU5)
Haha i believe nahla just conned people into answering his homework question lol
not really, I just wanted to see if the question was really that literal, I used this as a basis to answer other hw questions of similar manner.
Those are bad homework questions. It's all to often I see really bad teachings, really bad teachers, and really bad homework questions. I'm certain there is a conspiracy to poorly teach people C++ and make them feel stupid just so that existing C++ programmers can keep their jobs without competition...
Those are bad homework questions. It's all to often I see really bad teachings, really bad teachers, and really bad homework questions. I'm certain there is a conspiracy to poorly teach people C++ and make them feel stupid just so that existing C++ programmers can keep their jobs without competition...


I am not sure how serious you are. I guess you're joking about the conspiracy but about a teachers capabilities it depends entirely on both the teacher, the institution at which they are teaching and the level at which the subject is being learnt. This seems more like something you would do early on in British A-Level. However if your doing a university course that assumes no prior knowledge then its possible a bad teacher may give this sort of assignment.

Also that question really is badly explained/laid out. Is that really all they gave you to go on?
Topic archived. No new replies allowed.