Thread: Classes Help!!!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Absolutely delete it.

    The problem is that you need an implementation of a destructor, even if it's pure. Easier to not make it pure, since you have a pure function already. (The only reason to make a destructor pure is
    to make a class abstract when it has no natural pure functions.)
    Code:
    virtual ~GraphObj() {}
    You don't need to explicitly create a destructor in any of the derived classes.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Quote Originally Posted by CornedBee View Post
    Absolutely delete it.

    The problem is that you need an implementation of a destructor, even if it's pure. Easier to not make it pure, since you have a pure function already. (The only reason to make a destructor pure is
    to make a class abstract when it has no natural pure functions.)
    Code:
    virtual ~GraphObj() {}
    You don't need to explicitly create a destructor in any of the derived classes.
    Aha!

    I commented it out and it gave an error since line was private, so I made it protected.

    And then the destructor stuff, so I have:

    Code:
    class GraphObj
    {
    	public:
    		GraphObj(const string inputstr)
    		{
    			line = inputstr;
    		}
    		virtual ~GraphObj() {};
    		virtual void draw(Image& img) = 0;
    	protected:
    		string line;
    };
    Code:
    class Line : public GraphObj
    {
    	public:
    		Line(const string inputstr) : GraphObj(inputstr)
    		{
    		}
    		void draw(Image& img)
    		{
    			// stuff
    		}
    };
    No compile errors or warnings!!

    Now, my constructor in Line is completely blank... Do I even need it? Looks odd...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  3. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM