Thread View: perl.inline
1 messages
1 total messages
Started by Jim Avera
Tue, 26 Mar 2019 07:20
Abstract base classes with Inline:CPP ?
Author: Jim Avera
Date: Tue, 26 Mar 2019 07:20
Date: Tue, 26 Mar 2019 07:20
50 lines
5535 bytes
5535 bytes
Hi, Is there a way to make abstract base classes play well with
Inline::CPP ?
An xs wrapper is generated for every method in the base class, even
though the base class, being abstract, can never be instantiated
directly (only via a derived class which implements the virtual methods
not defined in the base). This causes compilation errors.
Here's an example:
#!/usr/bin/perl
use strict; use warnings; use v5.10;
package Some::Mumble::Pie;
use Inline CPP => config => namespace => 'Some';
use Inline CPP => <<'END_CPP' => CLEAN_AFTER_BUILD => 0;
#include <iostream>
using namespace std;
class Base {
public:
Base() { cout << "creating a Base()" << endl; }
virtual ~Base() { cout << "deleting a Base()" << endl; }
void run(int a) {
cout << "Base::run(" << a << ") called." << endl;
tick(a);
}
virtual void tick(int) = 0;
};
class Der : public Base {
public:
Der() { cout << "creating a Der()" << endl; }
virtual ~Der() { cout << "deleting a Der()" << endl; }
void tick(int a){ cout << "Der::tick(" << a <<") called." << endl; }
};
// int main() {
// Der *obj = new Der;
// obj->run(42);
// delete(obj);
// return 0;
// }
END_CPP
1;
my $obj = Some::Der->new();
$obj->run(42);
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads