Hi,
Could you tell me whether the following two statement are the same?
Derived class is derived from Base class.
1. Base* ptr1;
2. Derived * ptr2;
Does it mean ptr1 is the same as ptr2?
Thanks in advance,
Michael 5 1961
"Michael" <mi*******@gmai l.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Hi,
Could you tell me whether the following two statement are the same?
Derived class is derived from Base class.
1. Base* ptr1;
2. Derived * ptr2;
Does it mean ptr1 is the same as ptr2?
No.
The only thing you have listed are declarations. They could be set to point
the same address space, namely an address of an object of type Derived.
Then you could call any member functions of Base from the Base point and any
members of Derived from the derived pointer.
Note: Any virtual functions called from the address contained in Base* would
run from the derived classes data.
--
LTP
:)
Michael wrote:
...
Could you tell me whether the following two statement are the same?
Derived class is derived from Base class.
1. Base* ptr1;
2. Derived * ptr2;
No, they are not the same.
Does it mean ptr1 is the same as ptr2?
I don't understand what you mean here. Types of 'ptr1' and 'ptr2'? Values of
'ptr1' and 'ptr2'? Something else?
--
Best regards,
Andrey Tarasevich
Luc The Perverse wrote:
"Michael" <mi*******@gmai l.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Hi,
Could you tell me whether the following two statement are the same?
Derived class is derived from Base class.
1. Base* ptr1;
2. Derived * ptr2;
Does it mean ptr1 is the same as ptr2?
No.
The only thing you have listed are declarations. They could be set to point
the same address space, namely an address of an object of type Derived.
Then you could call any member functions of Base from the Base point and any
members of Derived from the derived pointer.
Note: Any virtual functions called from the address contained in Base* would
run from the derived classes data.
--
LTP
:)
So a Base point could point to either Base object (complete object) or
Derived object (incomplete object). A Derived point could only point to
Derived object? Right?
Why not use Base* points to Base object and Derived points to Derived
object?
"Michael" <mi*******@gmai l.comwrote in message
news:11******** *************@m 79g2000cwm.goog legroups.com
Luc The Perverse wrote:
>"Michael" <mi*******@gmai l.comwrote in message news:11******* *************** @i42g2000cwa.go oglegroups.com. ..
>>Hi,
Could you tell me whether the following two statement are the same? Derived class is derived from Base class.
1. Base* ptr1; 2. Derived * ptr2;
Does it mean ptr1 is the same as ptr2?
No.
The only thing you have listed are declarations. They could be set to point the same address space, namely an address of an object of type Derived.
Then you could call any member functions of Base from the Base point and any members of Derived from the derived pointer.
Note: Any virtual functions called from the address contained in Base* would run from the derived classes data.
-- LTP
:)
So a Base point could point to either Base object (complete object) or
Derived object (incomplete object). A Derived point could only point
to Derived object? Right?
Why not use Base* points to Base object and Derived points to Derived
object?
Suppose you want to store pointers to Base objects and pointers to Derived
objects in the same container --- or, more likely, pointers to Derived1
objects and pointers to Derived2 objects. How would you do it, given that
the container will only store one type of pointer? Answer: by making the
container store base Base pointers.
--
John Carson
Michael wrote:
Hi,
Could you tell me whether the following two statement are the same?
Derived class is derived from Base class.
1. Base* ptr1;
2. Derived * ptr2;
Does it mean ptr1 is the same as ptr2?
Thanks in advance,
Michael
You can assign a Derived* to ptr1, but you cannot assign a Base* to ptr2. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Gabriel Genellina |
last post by:
Hi
In the following code sample, I have:
- a Worker class, which could have a lot of methods and attributes. In
particular, it has a 'bar' attribute. This class can be modified as needed.
- a Base class (old-style) which defines a default class attribute 'bar'
too. I can't modify the source code of this class. Note that Workes does
not inherit from Base.
- a Derived class which must inherit from Base and is a wrapper around
Worker: it...
|
by: justanotherguy63 |
last post by:
Hi,
I am designing an application where to preserve the hierachy and for
code substitability, I need to pass an array of derived class object in
place of an array of base class object. Since I am using vector
class(STL), the compiler does not allow me to do this.
I do realize there is a pitfall in this approach(size of arrays not
matching etc), but I wonder how to get around this problem. I have a
class hierachy with abstract base...
|
by: Baski |
last post by:
Base class:
class AssetBase
{
string _clli;
public string CLLI
{
get
|
by: Andy |
last post by:
Hi all,
I have a site with the following architecture:
Common.Web.dll - Contains a CommonPageBase class which inherits
System.Web.UI.Page
myadd.dll - Contains PageBase which inherits CommonPageBase
- Contains myPage which inherits PageBase
Each of these classes overrides OnInit and ties an event handler
|
by: Jeff |
last post by:
The derived class below passes a reference to an object in its own
class to its base calss constructor. The code compiles and will run
successfully as long as the base class constructor does not attempt to
access the object -- since m_object is not actually created and
initizialized until after the base constructor has been called.
Any thoughts on the practice below?
class Base
{
public:
| |
by: Taran |
last post by:
Hi All,
I tried something with the C++ I know and some things just seem
strange.
consider:
#include <iostream>
using namespace std;
|
by: Dennis Jones |
last post by:
Hello,
I have a couple of classes that look something like this:
class RecordBase
{
};
class RecordDerived : public RecordBase
{
|
by: =?Utf-8?B?R2Vvcmdl?= |
last post by:
Hello everyone,
I met with a strange issue that derived class function can not access base
class's protected member. Do you know why?
Here is the error message and code.
error C2248: 'base::~base' : cannot access protected member declared in
|
by: cmonthenet |
last post by:
Hello,
I searched for an answer to my question and found similar posts,
but none that quite addressed the issue I am trying to resolve.
Essentially, it seems like I need something like a virtual static
function (which I know is illegal), but, is there a way to provide
something similar? The class that is the target of my inquiry is a
template class that interfaces to one of several derived classes
through a pointer to a base class. The...
|
by: alexl |
last post by:
I have 2 classes,
class base {
public:
some virtual functions
}
class derived : public base {
public:
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |