The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.24-0ubuntu0.18.04.15 (Linux)
File Line Function
/showthread.php 906 errorHandler->error




Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Smarter overloading method?
#1
I made this. 3 simple functions with overloads to cover all possible parameter combinations. The problem is that code lenght scales expotentially with number of parameters. Is there smarter/shorter way to make function with parameters that can be different types?
Code:
extern void object::Libr(){}

public object object::pick(point p) {
    goto(p);
    grab();
    return load;
}

public object object::pick(object o) {
    return pick(o.position);
}

public object object::pick(int cat) {
    return pick(radar(cat));
}

public void put(point p){
    goto(p);
    drop();
}

public void put(object o){
    put(o.position);
}

public void put(int cat){
    put(radar(cat));
}

public void transport(point what, point where){
    pick(what);
    put(where);
}

public void transport(point what, object where){
    transport(what, where.position);
}

public void transport(point what, int where){
    transport(what, radar(where));
}

public void transport(object what, point where){
    transport(what.position, where);
}

public void transport(object what, object where){
    transport(what.position, where.position);
}

public void transport(object what, int where){
    transport(what.position, radar(where));
}

public void transport(int what, point where){
    transport(radar(what), where);
}

public void transport(int what, object where){
    transport(radar(what), where.position);
}

public void transport(int what, int where){
    transport(radar(what), radar(where));
}


Messages In This Thread
Smarter overloading method? - by Smok - 02-02-2018, 01:29 PM
RE: Smarter overloading method? - by DomesticAnt - 03-24-2018, 01:57 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)