C++ help?

Z

Zach Dennis

I'm not a huge c++ guy, and I'm trying to help w/wxRuby development and
I've ran into an error. perhaps someone with more c++ knowledge can help
me out.

There is a classs wxPrintout in the the wxWindows library, I am trying
to wrap it for use in WxRuby. Whenever I try to create it

new wxPrintout()

it says I cannot instantiate the abstract class due to the following
members. Then it gives me the method signautre for a pure virtual method
OnPrintPage.

So I override wxPrintout in my file:

class wxPrintout{
public:
virtual bool OnPrintPage( int page )
}

Then it errors out because of a "class type redefinition". Any ideas how
to get around class type redefinition?

Thanks,

Zach
 
W

Wayne Vucenic

Hi Zach,

Since OnPrintPage is a pure virtual method in wxPrintout, you need to
derive a class from wxPrintout, and define OnPrintPage in that class.
Something like:

class wxPrintoutWrap : public wxPrintout
{
bool OnPrintPage( int page );
};

bool wxPrintoutWrap::OnPrintPage( int page )
{
// your code goes here

return true;
}

Hope this helps,

Wayne
 
D

Dave Burt

Zach Dennis said:
new wxPrintout()

it says I cannot instantiate the abstract class due to the following
members. Then it gives me the method signautre for a pure virtual method
OnPrintPage.

So I override wxPrintout in my file:

class wxPrintout{
public:
virtual bool OnPrintPage( int page )
}

Then it errors out because of a "class type redefinition".

You can redefine classes (heck, even individual objects) in Ruby, but not in
C++.
If you want a wxPrintout that is instantiable, you will need to define a
concrete subclass of wxPrintout:

class wxRubyPrintout : public wxPrintout
{
bool OnPrintPage( int page );
};
 
Z

Zach Dennis

Wayne said:
Hi Zach,

Since OnPrintPage is a pure virtual method in wxPrintout, you need to
derive a class from wxPrintout, and define OnPrintPage in that class.
Something like:

class wxPrintoutWrap : public wxPrintout
{
bool OnPrintPage( int page );
};

bool wxPrintoutWrap::OnPrintPage( int page )
{
// your code goes here

return true;
}

Thank you very much Wayne, this is exaclty what I need to see for
something to click in my head.

Zach
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,162
Messages
2,570,893
Members
47,432
Latest member
GTRNorbert

Latest Threads

Top