简体   繁体   中英

Are there pure abstract classes in C++?

There is a homework question which asks what construct in C++ is similar to a Java interface. An interface in Java can be referred to as a pure abstract class, and I know that C++ has abstract classes, but are pure abstract classes something that C++ officially has ?

Maybe from a C++ designer's viewpoint it doesn't, but technically it is possible to create an pure abstract class in C++ by making all methods abstract right?

I looked at this resource but I'm still confused after reading some of the answers...

Yes you can create an abstract class in c++

class A {

public:
    A() {};
    virtual ~A(){};
    virtual void temp() = 0;
};

int main () {
    A a; // compiler error
}
class Foo {
public:
    Foo();
    virtual ~Foo() {};
    virtual void bar() = 0;
}

Foo is a pure abstract class in C++ because it contains the method bar() which is a pure virtual method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM