From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11197 invoked by alias); 20 Nov 2013 16:42:24 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 11168 invoked by uid 89); 20 Nov 2013 16:42:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.7 required=5.0 tests=AWL,BAYES_50,RDNS_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: mail-oa0-f54.google.com Received: from Unknown (HELO mail-oa0-f54.google.com) (209.85.219.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 20 Nov 2013 16:41:43 +0000 Received: by mail-oa0-f54.google.com with SMTP id h16so4814970oag.41 for ; Wed, 20 Nov 2013 08:41:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=/A5f2lMsv6p8nDftdnWDPaqC5cucZYla/F2OxlKM8so=; b=EEFYL3JUet29ZaYbRilgmX2iM3khsBVSTmSqWQbJzoT/rmayQ1tQcjLJJHEObgEwob YJmxdBBT4UyAE4u+JydibWN0Sb/VPbSJ3tR4Jm8vrXDOJLqEiRCuZ4gtzFcDYb6qCwa3 kVpOBxAXwvcY/wUloifP7d9orA4aq2ku4bKM5v+OH3pYyOAyNKIKbIHGjFHcyigjOrUK cZOuZ5FClWbNC4ktXuNFCe0tvr0padP+rv53LILwwRfEQwS+RAGyCi7fznIBwKFif94G ix8RnukPQ1oagdlvaYP56ZL4SQoegl/RxmaGNsdIWhsIkPwvtq50CEYcKX1W5Ixf3vrE TQbw== X-Gm-Message-State: ALoCoQlpUU/WzuiTaqwpNTivFI0Dt6bmw0lAxeIRU9XIgSJdnkNhGtDDX7BQ4PY0X8dK+0c5uzteRdZkXT8Qicj4gnn8g/AJJaLNJw3fd6z0WqwlZ8z1GqxLrGnyp0O3Lc6OB21cBJ/lGbRyXyoo4jwAH0qLhi23TIV8F+2ccahznu6M9TlzV0eocC3vmMksNqDoFmMvo1uy MIME-Version: 1.0 X-Received: by 10.182.28.35 with SMTP id y3mr1181185obg.55.1384965695569; Wed, 20 Nov 2013 08:41:35 -0800 (PST) Received: by 10.60.145.144 with HTTP; Wed, 20 Nov 2013 08:41:35 -0800 (PST) In-Reply-To: <528CCCCD.3030601@gmail.com> References: <528CCCCD.3030601@gmail.com> Date: Wed, 20 Nov 2013 17:41:00 -0000 Message-ID: Subject: Re: virtual table From: Ian Lance Taylor To: Riccardo Manfrin Cc: gcc-help Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes X-SW-Source: 2013-11/txt/msg00148.txt.bz2 On Wed, Nov 20, 2013 at 6:53 AM, Riccardo Manfrin wrote: > > suppose I have three classes Foo, Bar, Zoo. > > Foo inherits from Bar, > Bar inherits from Zoo. > > Bar and Zoo are abstract classes (as defined here : > http://en.wikibooks.org/wiki/C%2B%2B_Programming/Classes/Abstract_Classes) > > The size of Foo shall account for the two pointers to Bar an Zoo vtables. For this kind of discussion it helps to show actual code. If I understand your description correctly, then your statement about the size of Foo is incorrect. #include class Zoo { virtual void zoo() = 0; }; class Bar : public Zoo { virtual void bar() = 0; }; class Foo : public Bar { void* v; }; int main() { std::cout << sizeof(Foo) << std::endl; } On my x86_64 system this prints 16: 8 for the single vtable pointer, 8 for the void* field. In other words, although Foo inherits from two classes as you suggest, there is still only one vtable pointer. Ian