🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.c
Article #309400

Re: Podklasy, nie-wskaźniki a vector

#309400
From: Borneq
Date: Fri, 18 Aug 2017 10:35
43 lines
1807 bytes
W dniu 18.08.2017 o 12:13, bartekltg pisze:
> Polimorfizm działa, jeśli masz wskaźniki.
> 
>> A w Pascalu na wskaźnikach a.wirtualna wołała o ile pamiętam z B
> 
> Prawie na pewno nie.

W Pascalu są tylko wskaźniki (chyba że przestarzały, nieużywany object 
zamiast class)
więc działa jak w C dla wskaźników,
#include <iostream>
using namespace std;

class A
{
public:
	virtual void v(){
		cout << "z A" << endl;
	}
};

class B: public A
{
public:
	void v() {
		cout << "z B" << endl;
	}
};

int main()
{
	A a;
	B b;
	a = b;
	a.v();
	B *pb = new B();
	A *pa = pb;
	pa->v();
     return 0;
}


Za drugim razem jest polimorfizm, za pierwszym zaskoczenie że nie ma.
Technical Details
Message-ID: <on6fte$h01$1@node1.news.atman.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
References: <on6425$5ia$1@node1.news.atman.pl> <c0fe2d57-1caf-41ac-823f-60a9f809eece@googlegroups.com> <on6d4p$e5i$1@node1.news.atman.pl> <on6d9h$e5i$2@node1.news.atman.pl> <a39015b2-45c2-40a2-a43d-84a542479345@googlegroups.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
From: Borneq <borneq@antyspam.hidden.pl>
Newsgroups: pl.comp.lang.c
Subject: Re: Podklasy, nie-wskaźniki a vector
Date: Fri, 18 Aug 2017 12:35:27 +0200
Organization: ATMAN - ATM S.A.
Lines: 43
Message-ID: <on6fte$h01$1@node1.news.atman.pl>
References: <on6425$5ia$1@node1.news.atman.pl> <c0fe2d57-1caf-41ac-823f-60a9f809eece@googlegroups.com> <on6d4p$e5i$1@node1.news.atman.pl> <on6d9h$e5i$2@node1.news.atman.pl> <a39015b2-45c2-40a2-a43d-84a542479345@googlegroups.com>
NNTP-Posting-Host: 91.239.205.105
Mime-Version: 1.0
X-Trace: node1.news.atman.pl 1503052527 17409 91.239.205.105 (18 Aug 2017 10:35:27 GMT)
X-Complaints-To: usenet@atman.pl
NNTP-Posting-Date: Fri, 18 Aug 2017 10:35:27 +0000 (UTC)
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1
In-Reply-To: <a39015b2-45c2-40a2-a43d-84a542479345@googlegroups.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit