S
S
sddvxd2018-01-30 23:58:11
C++ / C#
sddvxd, 2018-01-30 23:58:11

Why doesn't this link code work?

Good evening

#include <iostream>
#include <string>
#include "kwat.h"
using namespace std;

KWat& swap(KWat&, const KWat&);
void display(KWat&);

int main(){

  KWat box1(200,4.3,18);
  KWat box2(500,5.0,20);
  display(swap(box1,box2));
}

KWat& swap(KWat& ob, const KWat& cob){
  ob.price = cob.price;
  return ob;
}


void display(KWat& ob){
  cout<<"Price of box1: "<<ob.price;
}

The compiler says: invalid use of void
expression Set the return value to the method as a reference to an object

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
terrier, 2018-01-31
@sddvxd

using namespace std;
You don't have to do this and std::swap (which, as you know, returns void) will not be substituted instead of your swap variant
PS Well, and, of course, the swap function itself, which does not swap, is also worthy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question