MESSAGE
DATE | 2016-11-21 |
FROM | ruben safir
|
SUBJECT | Subject: [Learn] Fwd: when is the constructor called for an object
|
From learn-bounces-at-nylxs.com Mon Nov 21 03:37:24 2016 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: from www.mrbrklyn.com (www.mrbrklyn.com [96.57.23.82]) by mrbrklyn.com (Postfix) with ESMTP id 96D7F161315; Mon, 21 Nov 2016 03:37:24 -0500 (EST) X-Original-To: learn-at-nylxs.com Delivered-To: learn-at-nylxs.com Received: from [10.0.0.62] (flatbush.mrbrklyn.com [10.0.0.62]) by mrbrklyn.com (Postfix) with ESMTP id 66DD2161312 for ; Mon, 21 Nov 2016 03:37:21 -0500 (EST) References: To: learn-at-nylxs.com From: ruben safir X-Forwarded-Message-Id: Message-ID: <3226ea42-6b20-889e-cf03-8cd94f09044f-at-mrbrklyn.com> Date: Mon, 21 Nov 2016 03:37:21 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------5EE904AB482B6D8724D9991E" Subject: [Learn] Fwd: when is the constructor called for an object X-BeenThere: learn-at-nylxs.com X-Mailman-Version: 2.1.17 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: learn-bounces-at-nylxs.com Sender: "Learn"
This is a multi-part message in MIME format. --------------5EE904AB482B6D8724D9991E Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit
constructor confusion
The real problem here is that then new Strousrup text seems to say that use of {} can be used in lew of "= new" nominclature, but it doesn't seem to work like he suggests, which means I'm not understanding what he wrote, or what he wrote wasn't clear ;)
--------------5EE904AB482B6D8724D9991E Content-Type: message/rfc822; name="when is the constructor called for an object.eml" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="when is the constructor called for an object.eml"
Path: reader2.panix.com!panix!not-for-mail From: Popping mad Newsgroups: alt.comp.lang.learn.c-c++ Subject: when is the constructor called for an object Date: Mon, 21 Nov 2016 02:24:54 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Message-ID: NNTP-Posting-Host: www.mrbrklyn.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: reader2.panix.com 1479695094 17604 96.57.23.82 (21 Nov 2016 02:24:54 GMT) X-Complaints-To: abuse-at-panix.com NNTP-Posting-Date: Mon, 21 Nov 2016 02:24:54 +0000 (UTC) To: learn-at-nylxs.com User-Agent: Pan/0.140 (Chocolate Salty Balls; GIT b8fc14e git.gnome.org/git/pan2) Xref: panix alt.comp.lang.learn.c-c++:246544
I have a class class{ public: Node(Node *){}; Node(){}; Node* left() { return _left; } left(Node *in) { _left=in; }
private: Node * _left; Node * _right;
and in another class I call
Node * tmp;
and later I want to allocate its memory (without using new)
I use
tmp = nullptr;
I can't seem to use tmp{nullptr};
and when I try tmp(nullptr){};
if says tmp is not a function
when is the constructor called?
--------------5EE904AB482B6D8724D9991E Content-Type: message/rfc822; name="Re: when is the constructor called for an object.eml" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="Re: when is the constructor called for an object.eml"
Path: reader2.panix.com!panix!goblin3!goblin.stu.neva.ru!nntp-feed.chiark.greenend.org.uk!ewrotcd!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ike Naar Newsgroups: alt.comp.lang.learn.c-c++ Subject: Re: when is the constructor called for an object Date: Mon, 21 Nov 2016 08:31:22 -0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Date: Mon, 21 Nov 2016 08:31:22 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="cae1db1297ffc0cc56488ebcd6981047"; logging-data="1739"; mail-complaints-to="abuse-at-eternal-september.org"; posting-account="U2FsdGVkX1/YdQB+sX/HGZcSl8pJnWKF" User-Agent: slrn/0.9.9p1 (NetBSD) Cancel-Lock: sha1:mtHO+S5Us0WODepW9vX9YZersrs= Xref: panix alt.comp.lang.learn.c-c++:246549
On 2016-11-21, Popping mad wrote: > I have a class
> class{
You probably meant
class Node {
> public: > Node(Node *){}; > Node(){}; > Node* left() > { > return _left; > } > left(Node *in)
You probably meant
void left(Node *in)
> { > _left=in; > } > > private: > Node * _left; > Node * _right;
};
> and in another class I call > > Node * tmp; > > and later I want to allocate its memory (without using new)
Why can't you use new?
> I use > > tmp = nullptr; > > I can't seem to use > tmp{nullptr}; > > and when I try > tmp(nullptr){}; > > if says tmp is not a function > > when is the constructor called?
The constructur is called when an instance of class Node is created. E.g. like this:
Node *px = new Node; /* constructor Node() is called */ Node *py = new Node(px); /* constructor Node(Node*) is called */ Node z; /* constructor Node() is called */ Node *pz = &z; Node w(z); /* constructor Node(Node*) is called */ Node *pw = &w; Node *
--------------5EE904AB482B6D8724D9991E Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline
_______________________________________________ Learn mailing list Learn-at-nylxs.com http://lists.mrbrklyn.com/mailman/listinfo/learn
--------------5EE904AB482B6D8724D9991E--
|
|