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

Pages: 1-

C++ abstract bullshite

Name: melting void 2011-12-16 0:05

I have an abstract class (it has 1 member, which is a pure virtual function) which we'll call R, and I want a member function of some other class to take as an argument a reference to any class that inherits from R.

How should I declare this member function?

Name: Anonymous 2011-12-16 0:06

See if your tool suite has a utility for going to stackoverflow.

Name: Anonymous 2011-12-16 5:36

lisp

Name: Anonymous 2011-12-16 6:17

>>1
Ha ha, "member function". I just find it hilarious for some reason.

OP, just pass a reference to R, what the hell is yo problem?

Name: Anonymous 2011-12-16 11:54

>>1

Pass a reference to R. An R instance cannot be created anyway.

Name: Anonymous 2011-12-16 12:59

>>5
That's what I was trying, but it gives me an error.

class R {
        public:
        virtual void poo() = 0;
};

class P : public R {
        public:
        void poo() { cout << "Hello" << endl; }
};

class T {
        public:
        T(P& p);
};

int main() {
        T myt = new T(new P());
}


no matching function for call to `T::T(P*)'
candidates are: T::T(const T&)
                T::T(R&)

Name: Anonymous 2011-12-16 13:10

>>6
Delete both `new`'s.

Name: Anonymous 2011-12-16 13:14

Name one thing that makes less sense than C++ syntax. You can't.

Name: Anonymous 2011-12-16 13:14

>>6
Also, you forgot ``virtual'' on P::foo().
Also, you forgot to implement the constructor.
Also, the preferred form of initialization is "T myt(P());"
Also, something tells me that when you'd implement the constructor, you are going to try to save the reference to the passed P instance and have your shit blown up when it's destroyed before `myt`.

Name: /THREAD 2011-12-16 13:22

I solved it.  Had to use a pointer instead of a reference.

Name: Anonymous 2011-12-16 13:24

>>8
That has nothing to do with syntax, fagdrizzle.

Name: Anonymous 2011-12-16 13:38

>>11
Neither has your post, mouthbreather.

Name: Anonymous 2011-12-16 14:15

>>10
Good old C++, provide duplicate features that are actually worse than the ones they replace in C. It's hard to imagine how one could intentionally design a worse language.

Name: Anonymous 2011-12-16 15:53

>>13
CHALLENGE: ACCEPTED

Name: Anonymous 2011-12-16 16:25

>>14
I didn't know Bjarne posted here!

Name: Anonymous 2011-12-17 2:43

= 0

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