Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

why seeples no interfaces?

Name: Anonymous 2012-01-14 0:50


#include<iostream>

using namespace std;

class A {
public:

  A() {
  }

  virtual ~A() {
  }

  void waka() {
    cout << "WakA!";
  }

};


class IWoopaWaka {
public:
  IWoopaWaka() {
  }

  virtual ~IWoopaWaka() {
  }

  virtual void waka() = 0;
  virtual void woopa() = 0;
};

class B : public IWoopaWaka, public A {
public:
  B() : A() {
  }

  virtual ~B() {
  }

  void woopa() {
    cout << "Woooopa!";
  }
};


int main(int argc, char** argv) {
  IWoopaWaka* wapa = new B();
  wapa->waka();
  wapa->woopa();
  delete wapa;
  return 0;
}


$g++ m.cpp
m.cpp: In function ‘int main(int, char**)’:
m.cpp:49: error: cannot allocate an object of abstract type ‘B’
m.cpp:34: note:   because the following virtual functions are pure within ‘B’:
m.cpp:30: note:         virtual void IWoopaWaka::waka()


#include<iostream>

using namespace std;

class A {
public:

  A() {
  }

  virtual ~A() {
  }

  void waka() {
    cout << "WakA!";
  }

};


class IWoopaWaka {
public:
  IWoopaWaka() {
  }

  virtual ~IWoopaWaka() {
  }

  virtual void waka() = 0;
  virtual void woopa() = 0;
};

class B : public IWoopaWaka, public A {
public:
  B() : A() {
  }

  virtual ~B() {
  }

  void waka() {
    A::waka();
  }

  void woopa() {
    cout << "Woooopa!";
  }
};


int main(int argc, char** argv) {
  IWoopaWaka* wapa = new B();
  wapa->waka();
  wapa->woopa();
  delete wapa;
  return 0;
}


$g++ m.cpp
$a.out
WakA!Woooopa!$

Name: Anonymous 2012-01-14 1:01


class A {
  public void waka() {
    System.out.printf("WakA!");
  }
}

interface IWoopaWaka {
  void waka();
  void woopa();
}

class B extends A implements IWoopaWaka {
  public void woopa() {
    System.out.printf("Woooopa!");
  }
}

class M {
  public static void main(String[] args) {
    IWoopaWaka waka = new B();
    waka.waka();
    waka.woopa();
  }
}



$javac A.java
$java M
WakA!Woooopa!$

Name: Anonymous 2012-01-14 1:11

>>1
Learn what a interface is and you'll see why it doesn't have them

Name: Anonymous 2012-01-14 1:20

>>3
umena cuz it cun do multiple inheritence, it no need no interfaces? My example say otherwise.

Name: Anonymous 2012-01-14 1:29

>>4
Let me restate what I just said:

Learn what a interface is and you'll see why it doesn't have them

Name: Anonymous 2012-01-14 1:32

>>5
umena cuz it cun do multiple inheritence, it no need no interfaces? My example say otherwise.

Name: Anonymous 2012-01-14 1:43

#include <assert.h>

int main(){
  assert(multiple_inheritence == AIDS);
  return 0;
}


Assertion didn't fail.

Name: Anonymous 2012-01-14 1:45

>>6
sepples programmers really are this dumb aren't they? If you're unwilling to learn what a interface in java really is then you have no hope.

Name: Anonymous 2012-01-14 1:50

virtual deconstructor....why?

Name: Anonymous 2012-01-14 1:56

>>8
but..buta..seeples no has no replacement for interfaces. There seems to be no way. Can you do it the better way in seeples? I was actually going to ask if anyone knew of a less archaic method than:


#include<iostream>

using namespace std;

class A {
public:
  virtual ~A() {}

  void waka1() { cout << "WakA1!"; }
  void waka2() { cout << "WakA2!"; }
  void waka3() { cout << "WakA3!"; }
  void waka4() { cout << "WakA4!"; }
  void waka5() { cout << "WakA5!"; }
  void waka6() { cout << "WakA6!"; }
  void waka7() { cout << "WakA7!"; }
  void waka8() { cout << "WakA8!"; }
};


class IWoopaWaka {
public:
  virtual ~IWoopaWaka() {}
  virtual void waka1() = 0;
  virtual void waka2() = 0;
  virtual void waka3() = 0;
  virtual void waka4() = 0;
  virtual void waka5() = 0;
  virtual void waka6() = 0;
  virtual void waka7() = 0;
  virtual void waka8() = 0;
  virtual void woopa() = 0;
};

class B : public A, public IWoopaWaka {
public:
  B() : A() { }

  virtual ~B() {}

  void woopa() { cout << "Woooopa!"; }
};


int main(int argc, char** argv) {
  IWoopaWaka* wapa = new B();
  wapa->waka1();
  wapa->waka2();
  wapa->waka3();
  wapa->waka4();
  wapa->waka5();
  wapa->waka6();
  wapa->waka7();
  wapa->waka8();
  wapa->woopa();
  delete wapa;
  return 0;
}

$g++ m.cpp
m.cpp: In function ‘int main(int, char**)’:
m.cpp:46: error: cannot allocate an object of abstract type ‘B’
m.cpp:35: note:   because the following virtual functions are pure within ‘B’:
m.cpp:24: note:         virtual void IWoopaWaka::waka1()
m.cpp:25: note:         virtual void IWoopaWaka::waka2()
m.cpp:26: note:         virtual void IWoopaWaka::waka3()
m.cpp:27: note:         virtual void IWoopaWaka::waka4()
m.cpp:28: note:         virtual void IWoopaWaka::waka5()
m.cpp:29: note:         virtual void IWoopaWaka::waka6()
m.cpp:30: note:         virtual void IWoopaWaka::waka7()
m.cpp:31: note:         virtual void IWoopaWaka::waka8()

#include<iostream>

using namespace std;

class A {
public:
  virtual ~A() {}

  void waka1() { cout << "WakA1!"; }
  void waka2() { cout << "WakA2!"; }
  void waka3() { cout << "WakA3!"; }
  void waka4() { cout << "WakA4!"; }
  void waka5() { cout << "WakA5!"; }
  void waka6() { cout << "WakA6!"; }
  void waka7() { cout << "WakA7!"; }
  void waka8() { cout << "WakA8!"; }
};


class IWoopaWaka {
public:
  virtual ~IWoopaWaka() {}
  virtual void waka1() = 0;
  virtual void waka2() = 0;
  virtual void waka3() = 0;
  virtual void waka4() = 0;
  virtual void waka5() = 0;
  virtual void waka6() = 0;
  virtual void waka7() = 0;
  virtual void waka8() = 0;
  virtual void woopa() = 0;
};

class B : public A, public IWoopaWaka {
public:
  B() : A() { }

  virtual ~B() {}

  void woopa() { cout << "Woooopa!"; }

  void waka1() { A::waka1(); }
  void waka2() { A::waka2(); }
  void waka3() { A::waka3(); }
  void waka4() { A::waka4(); }
  void waka5() { A::waka5(); }
  void waka6() { A::waka6(); }
  void waka7() { A::waka7(); }
  void waka8() { A::waka8(); }
};

int main(int argc, char** argv) {
  IWoopaWaka* wapa = new B();
  wapa->waka1();
  wapa->waka2();
  wapa->waka3();
  wapa->waka4();
  wapa->waka5();
  wapa->waka6();
  wapa->waka7();
  wapa->waka8();
  wapa->woopa();
  delete wapa;
  return 0;
}

$g++ m.cpp
$a.out
WakA1!WakA2!WakA3!WakA4!WakA5!WakA6!WakA7!WakA8!Woooopa!


Seeples can't seem to choose the non pure virtual method when resolving ambiguous method calls. For some reason, it still tries to call the pure virtual one when a real method is available. y u do this seeples? y u make me reimplement all doos methods and make em call the non virtual method. y u do dis to me?

Name: Anonymous 2012-01-14 1:57

>>10
If you're unwilling to learn what a interface in java really is then you have no hope.

Name: Anonymous 2012-01-14 1:57

>>9

I need it cuz I call delete on a IWakaWoopa* when it is actually a pointer to a B.

Name: Anonymous 2012-01-14 2:09

>>11

well, from what I have read a while eago, it was somzing leik:

interface IWakaWoopa {
  void waka();
  void woopa();
}

begin equivalnet ta:

abstract class IWakaWoopa {
  abstract public void waka();
  abstract public void woopa();
}

cept ders da real unfortunate effect of not bein aba ta do da:

class B extends A implements IWakaWoopa {


A.java:20: interface expected here
class B extends A implements IWoopaWaka {
                             ^


aww shucks.

Some one would think that maybe,


class IWakaWoopa {
public:
  virtual ~IWakaWoopa() {}
  virtual void waka() = 0;
  virtual void woopa() = 0;
}


would be equivalent, but what do ya know, it ain't. An that makes me feel darn rotten.

Name: Anonymous 2012-01-14 2:31

>>13

public interface i {
  public void faggot();
}

public class c{
  public void faggot() { }
}

public class ic implements i {
  public void faggot() { }
}



ic and c are exactly the same except for one feature: ic can be abstracted to an `i' object unlike `c' class

consider the following:

struct geometric_shape {
  int (*area)(struct geometric_shape);
}

struct square {
  int (*area)(struct geometric_shape);
  int (*anus)(struct square);
  int fuckmehard;
}

int main()
{
  struct sqaure sq;
  struct *geometric_shape gs = &sq;
  printf("%d\n",gs->area(gs));
}

Name: Anonymous 2012-01-14 2:36

>>14
tl;dr: a interface is just a binding agreement to the JVM that said class will contain said method calls.

the structs on the bottom do the exact same thing an interface implement class would except C doesn't require compiler checking for shit like that and you'd probably have to cast &sq to (geometric_shape)

Name: Anonymous 2012-01-14 2:45

>>14

welp what do ya know? I had no idea you could provide methods with no implementation like that. Is this a new feature since java 5?

Name: Anonymous 2012-01-14 2:48

>>15

Thanks for the info. I think we can all agree that C is da best for those who know how to use it well. I wish seeples din't have so many kinks in it, but oh well. You just to develop some practices to get around them.

Name: Anonymous 2012-01-14 2:51

>>17
you can use C++ like C, C is a subset of C++ and it's father language.

Name: Anonymous 2012-01-14 2:55

>>18

yeah, but if I start passing around structures of function pointers, my coworkers will throw me out of a 5 story window. But I can do it at home ^_^

Name: Anonymous 2012-01-14 3:16

>>18
more is more!
no it's not.

Name: Anonymous 2012-01-14 3:18

>>20

it does contain a C subset

I'm not claiming this is C11,C99,C89,etc... just a subset

Name: Anonymous 2012-01-14 3:21

>>21
my point is that less is more. more is not more. if you don't understand this you are a shit programmer.

Name: Anonymous 2012-01-14 3:38

>>22
I'm in no way shape or form claiming C++, Java , etc > C because they have more functionality.

He clearly is doing a C++ group project for work as that's what it sounds like and it's good for him to know you can use C in C++.

Name: Anonymous 2012-01-14 4:06

>>22

are you saying that C++ should handle these cases itself, rather than forcing the user to fall back on C when it becomes necessary? I agree that would yield a simpler, more elegant, and easier to learn language. But we aren't talking about what would be better. We are just talking about how to wrangle this monster that is C++, because we have to deal with it a lot, and unfortunately, exposing all of the ways in which it is shitty will not change the fact that many of us have to use it everyday. So instead, we must develop tricks, techniques, and hacks to get around seeples's blotched parts.

Name: Anonymous 2012-01-14 4:11

>>24
there's a much easier way to do this using classes in c++


/* Code left as an exercise for the reader */

Name: Anonymous 2012-01-14 4:18

>>25

are you referring to the general structure of function pointers way, or the way done in the op where each method is reimplemented to specifically use the non virtual one? If you can do it better than the latter then please disclose. I don't want to have to do it this way forever gosh darn it.

Name: Anonymous 2012-01-14 4:54

#define struct interface

thread over

Name: Anonymous 2012-01-14 7:19

>>2
That's horrible. waka() from A is made to implement waka() from IWoopaWaka even though it doesn't extend it. Be glad it doesn't work in C++.

The following would work:

#include<iostream>

using namespace std;

class IWoopaWaka {
public:
  virtual ~IWoopaWaka() {}

  virtual void waka() = 0;
  virtual void woopa() = 0;
};

class A : public IWoopaWaka {
public:
  virtual ~A() {}

  void waka() {
    cout << "WakA!";
  }
};

class B : public A {
public:
  void woopa() {
    cout << "Woooopa!";
  }
};


int main(int argc, char** argv) {
  IWoopaWaka* wapa = new B();
  wapa->waka();
  wapa->woopa();
  delete wapa;
  return 0;
}


>>9
When a derived class is deleted through a pointer to a base class with a non-virtual destructor, the results are undefined. In practice, if the class doesn't contain any data members, whether it's virtual or not typically doesn't matter, but any C++ programmer should know that you shouldn't rely on undefined behaviour.

>>17
C++ has a few kinks, but nothing described here. The problem here is incompetent programmers.

Name: Anonymous 2012-01-14 7:21

Oops, was trying to get rid of those unnecessary constructor/destructor definitions, but forgot about ~A().

Name: Anonymous 2012-01-14 12:34

Use a 2012 language and switch to C#.

Name: Anonymous 2012-01-14 13:23

why u no XDDDDDDDDD
Back to Reddit,[/i]``please"![/i]

Name: Anonymous 2012-01-14 13:26

Interfaces? Fuck off back to your cubicle.

Name: Anonymous 2012-01-14 14:01

>>30
C#

back to /g/ with you, ``faggot''

Name: Anonymous 2012-01-14 19:12

>>28

Thanks, but what if I don't want A to be an abstract class? As it is, it has one pure virtual method, woopa, correct? What if A is supposed to exist independently of woopaing, and not be abstract?

Name: Anonymous 2012-01-14 19:14

>>31

no, I must remain so that you can better practice ur bbcodez when u tra and drive ma aways!

Name: Anonymous 2012-01-14 19:24

>>32
yesh, I prefer duck typing. quack quack lolzzzz lol quakc.

Name: Anonymous 2012-01-14 20:34

>>36
'lol'ing is about the extent of your mental capacity.

Name: Anonymous 2012-01-14 22:48

>>37

I can also quack, so I implicitly satisfy the lolling duck interface

Don't change these.
Name: Email:
Entire Thread Thread List