🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: perl.inline
Article #1

Abstract base classes with Inline:CPP ?

#1
From: Jim Avera
Date: Tue, 26 Mar 2019 07:20
50 lines
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);
Technical Details
Message-ID: <41c7167f-0fa3-3a1b-84b6-efbb818a94f0@gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!apf9.newsdeef.eu!nntp.perl.org

Show Full Headers
Complete Article Headers
Message-ID: <41c7167f-0fa3-3a1b-84b6-efbb818a94f0@gmail.com>
Subject: Abstract base classes with Inline:CPP ?
Date: Tue, 26 Mar 2019 00:20:42 -0700
From: jim.avera@gmail.com (Jim Avera)
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!apf9.newsdeef.eu!nntp.perl.org
Newsgroups: perl.inline
Return-Path: <jim.avera@gmail.com>
Mailing-List: contact inline-help@perl.org; run by ezmlm
Delivered-To: mailing list inline@perl.org
Received: (qmail 1465 invoked from network); 26 Mar 2019 07:20:51 -0000
Received: from xx1.develooper.com (207.171.7.115) by x6.develooper.com with
Received: from localhost (xx1.develooper.com [127.0.0.1]) by localhost
 (Postfix) with ESMTP id 2C00A7CF29 for <perlmail-inline@onion.perl.org>; Tue,
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mx3.develooper.com
X-Spam-Status: No, score=-2.0 required=6.0 tests=BAYES_00,DKIM_SIGNED,
 DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE autolearn=ham
 version=3.3.1
Received: from xx1.develooper.com (xx1.develooper.com [127.0.0.1]) by
 localhost (Postfix) with SMTP id 8CB7C7C1A7 for
Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com
 [209.85.210.180]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No
 client certificate requested) by xx1.develooper.com (Postfix) with ESMTPS id
Received: by mail-pf1-f180.google.com with SMTP id i17so7680753pfo.6 for
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com;
 s=20161025;
 h=to:reply-to:from:subject:message-id:date:user-agent:mime-version
 :content-transfer-encoding:content-language;
 bh=uBj8keGVW0HSgnvIi8sYGA7Yjno3dqVhwhwM4J/oeJw=;
 b=vdbXJ0aF1ap28Ub1fSpETJXKYiiaAr+oSxVvjFxn1oxATLbPsOz93kViuppkq/CAn9
 zFKC704+DIXawjJZB0RSbqNgmFD2zxNESSKf6Ht1EMqGJSdODN6d3QxH05c27+M2tiE0
 TJwSv/kpOy6MVsoVt0sDB4AJGW+eu6lumQoFQyx2S/BN8fVaR6CKxZ9BP7HyS54qZ3Wa
 t1IPjJKWgCgCER+rmMdQyxepeT4LkHUaC/yNXjVf10rMGJHCcCdM0WnpI6PgYqDoYbOI
 3C4ulP6sp/Vvb8zuaijjdAcchE1P50D/8x6tHuxPiqZ0B3E7nsd892SxKGJ3wqZHsrKA 2pTg==
X-Gm-Message-State: APjAAAWc+0sysmBQommrehIOberTwSmsYhCMj14hHp50f3H5qCnoug0i
 SF4zom3PxoKq7QzSl50vxKDJMi25
X-Received: by 2002:a63:d709:: with SMTP id d9mr11001909pgg.38.1553584843679;
Received: from [192.168.1.111] (c-73-71-160-195.hsd1.ca.comcast.net.
 [73.71.160.195]) by smtp.googlemail.com with ESMTPSA id
 d2sm21547390pgg.47.2019.03.26.00.20.42 for <inline@perl.org> (version=TLS1_2
 -0700 (PDT)
To: inline@perl.org
Reply-To: jim.avera@gmail.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
 Thunderbird/60.5.1
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Content-Language: en-US
X-PMX-Version: 5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data:
 2019.3.26.71215
X-PMX-Spam: Gauge=X, Probability=10%, Report=' TO_IN_SUBJECT 0.5, HTML_00_01
 0.05, HTML_00_10 0.05, BODYTEXTP_SIZE_3000_LESS 0, BODY_SIZE_1300_1399 0,
 BODY_SIZE_2000_LESS 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0,
 DATE_TZ_NA 0, DKIM_ALIGNS 0, DKIM_SIGNATURE 0, NO_CTA_URI_FOUND 0,
 NO_URI_FOUND 0, NO_URI_HTTPS 0, REPLYTO_SAMEAS_FROM 0, SPF_PASS 0,
 WEBMAIL_SOURCE 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __DKIM_ALIGNS_1 0,
 __DKIM_ALIGNS_2 0, __DQ_NEG_HEUR 0, __DQ_NEG_IP 0, __FRAUD_MONEY_CURRENCY 0,
 __FRAUD_MONEY_CURRENCY_DOLLAR 0, __FRAUD_WEBMAIL 0, __FRAUD_WEBMAIL_FROM 0,
 __FRAUD_WEBMAIL_REPLYTO 0, __FROM_GMAIL 0, __FUR_RDNS_GMAIL 0, __HAS_FROM 0,
 __HAS_MSGID 0, __HAS_REPLYTO 0, __HELO_GMAIL 0, __HIGHBITS 0,
 __MIME_TEXT_ONLY 0, __MIME_TEXT_P 0, __MIME_TEXT_P1 0, __MIME_VERSION 0,
 __MOZILLA_USER_AGENT 0, __NO_HTML_TAG_RAW 0, __PHISH_SPEAR_STRUCTURE_1 0,
 __RDNS_WEBMAIL 0, __REPLYTO_SAMEAS_FROM_ACC 0, __REPLYTO_SAMEAS_FROM_ADDY 0,
 __REPLYTO_SAMEAS_FROM_DOMAIN 0, __SANE_MSGID 0, __TO_IN_SUBJECT 0,
 __TO_MALFORMED_2 0, __TO_NO_NAME 0, __USER_AGENT 0, __X_GOOGLE_DKIM_SIGNATURE
 0, __YOUTUBE_RCVD 0, __blackholes.mail-abuse.org_ERROR ,
 __zen.spamhaus.org_ERROR '
Approved: news@nntp.perl.org