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

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 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.

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