Can I use `abstract` keyword in C++ class

2020-02-11 23:26发布

Can we write abstract keyword in C++ class?

标签: c++ keyword
10条回答
相关推荐>>
2楼-- · 2020-02-11 23:51
#define abstract
查看更多
Rolldiameter
3楼-- · 2020-02-11 23:52

No, you can't use abstract as a keyword because there is no such keyword available in C++.

If you want make a class as an in C++ abstract you can declare at least one function as pure virtual function.

But in derived class you must provide definition else its give compilation error .

Example:

class A
{
public:
  virtual void sum () = 0;
};

note:

You can used abstract as a variable name, class name because, as I told you, abstract is not a keyword in C++.

查看更多
Root(大扎)
4楼-- · 2020-02-11 23:57

It is a keyword introduced as part of the C++/CLI language spefication for the .NET framework.

查看更多
家丑人穷心不美
5楼-- · 2020-02-11 23:59

No, C++ has no keyword abstract. However, you can write pure virtual functions; that's the C++ way of expressing abstract classes.

查看更多
登录 后发表回答