Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

instantiation problem 1

Status
Not open for further replies.

HyperEngineer

Programmer
May 8, 2002
190
US
I have the following code:

This is in a .cpp file that instantiates the class.
Code:
  int port_number = 1;
  unsigned int input_buffer_size = 4096;
  unsigned int output_buffer_size = 1024;
  long baud_rate = 9600;
  char parity = 'N';
  int word_size = 8;
  int stop_bits = 1;
  int dtr = SET;
  int rts = RESET;
  int xon_xoff = DISABLE;
  int rts_cts = DISABLE;
  int dtr_dsr = DISABLE;

  m_pVTTermPort = new CVT100Port(this->m_hWnd,
                             port_number,
                             input_buffer_size,
                             output_buffer_size,
                             baud_rate,
                             parity,
                             word_size,
                             stop_bits,
                             dtr,
                             rts,
                             xon_xoff,
                             rts_cts,
                             dtr_dsr);

I get this error:


VT100TermDlg.cpp(195) : error C2259: 'CVT100Port' : cannot instantiate abstract class due to following members:
vt100port.h(14) : see declaration of 'CVT100Port'


This is the declaration of the base class (which is a derived class from another derived class)in the .h file:

Code:
class CVT100Port : public CWin32Port  
{
public:
	CVT100Port(HWND notify_window,
                   int port_number,
                   unsigned int input_buffer_size = 4096,
                   unsigned int output_buffer_size = 1024,
                   long baud_rate = UNCHANGED,
                   char parity = UNCHANGED,
                   int word_length = UNCHANGED,
                   int stop_bits = UNCHANGED,
                   int dtr = SET,
                   int rts = RESET,
                   int xon_xoff = DISABLE,
                   int rts_ctr = DISABLE,
                   int dtr_dsr = DISABLE);

	virtual ~CVT100Port();
protected:
	void TxNotify();
	void RxNotify(int byte_count);
	const HWND m_hNotifyWindow;
};

This is the implementation in the .cpp file:

Code:
CVT100Port::CVT100Port(HWND notify_window,
                       int port_number,
                       unsigned int input_buffer_size,
                       unsigned int output_buffer_size,
                       long baud_rate,
                       char parity,
                       int word_length,
                       int stop_bits,
                       int dtr,
                       int rts,
                       int xon_xoff,
                       int rts_cts,
                       int dtr_dsr): CWin32Port(port_number,
                                input_buffer_size,
                                output_buffer_size,
                                baud_rate,
                                parity,
                                word_length,
                                stop_bits,
                                dtr,
                                rts,
                                xon_xoff,
                                rts_cts,
                                dtr_dsr),
                        m_hNotifyWindow(notify_window)
{

}

The class that this is derived from is declared in another .h file:

Code:
  CWin32Port(int port_number,
             unsigned int InputBufferSize = 2048,
             unsigned int OutputBufferSize = 2048,
             long baud_rate = UNCHANGED,
             char parity = UNCHANGED,
             int word_length = UNCHANGED,
             int stop_bits = UNCHANGED,
             int dtr = SET,
             int rts = RESET,
             int xon_xoff = DISABLE,
             int rts_cts = DISABLE,
             int dtr_dsr = DISABLE);

And this is the implementation in the .cpp file:

Code:
  CWin32Port::CWin32Port(int port_number,    // 1,2,3 etc.
              unsigned int InputBufferSize,  // 2048
              unsigned int OutputBufferSize, // 2048
              long baud_rate,                // UNCHANGED
              char parity,                   // UNCHANGED
              int word_length,               // UNCHANGED
              int stop_bits,                 // UNCHANGED
              int dtr,                       // SET
              int rts,                       // RESET
              int xon_xoff,                  // DISABLE
              int rts_cts,                   // DISABLE
              int dtr_dsr                    // DISABLE
                ) : m_TxQueue(OutputBufferSize),
                    m_RxQueue(InputBufferSize)
{

}

I've run out of things to try. But it seems I'm missing something basic. Thanks for the help.

HyperEngineer
If it ain't broke, it probably needs improvement.
 
It's not the constructor that is the problem. The problem is that CVT100Port or its base class CWin32Port, or CWin32Port's base class if it has one, has a pure virtual method that has not been implemented. (Pure virtual means virtual something = 0;).

Check these classes for any pure virtual functions, and make sure you give them an implementation in CVT100Port, even if the implementation is empty. Once you do that, CVT100Port won't be an abstract class any more and you will be able to create an instance of it.
 
That was it. I had a typo. The virtual function was called out in the base class of CWin32Port and defined in CWin32Port, but had a typo in it. Instead of TxFreeSpace() I had TXFreeSpace(). Thanks for the uolj.

HyperEngineer
If it ain't broke, it probably needs improvement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top