Specific Class

Hello. I need to declare a class which must not allow making objects of it. I should not use virtual functions. Thank you in advance !
You are talking about an abstract class.

You cannot make one without at least one pure virtual function.

Or a constructor that just raises an exception...
Thank you Duoas. Could you just explain me what "a constructor that just raises an exception" means ?
1
2
3
4
5
6
7
8
class AlwaysFail
  {
  public:
    explicit AlwaysFail()
      {
      throw 0;
      }
  };

Such a class cannot be instantiated, since it throws an exception every time you try to create one.
O'kay, this works. But unfortunately, in my case that class should be base class. And the derived classes must allow making objects of them. Sorry , may be I've confused you by not saying the whole problem. Thanks again.
I think you need to review the mechanics of inheritance. Either solution will work for your needs, though I suspect that if this is homework you are doing that your professor wants to see a pure virtual function in an abstract class.
:)
Yeah, it was a homework, but when it was gaven to us, we hadn't been taught nothing about virtual functions or abstract classes. That was the reason i wanted to avoid using pure virtual fuction. Anyway... thanks for your help!
Best wishes,
MrProfit
Topic archived. No new replies allowed.