Instantiating class

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 11
Reputation: jack1234 is an unknown quantity at this point 
Solved Threads: 0
jack1234 jack1234 is offline Offline
Newbie Poster

Instantiating class

 
0
  #1
Jul 13th, 2008
Is this two ways of instantiating class both acceptable?(My intention is to create CBox on stack instead of heap)


CBox a=CBox(1);
CBox b(2);

Definition of CBox is as followed:

  1. class CBox
  2. {
  3. public:
  4. int abc;
  5. CBox(int var){
  6. abc=var;
  7. }
  8.  
  9. };
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,416
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 248
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Instantiating class

 
1
  #2
Jul 13th, 2008
Are you new ing? If so, that object is on the 'heap'.

Are you instantiating an object within a function? If so, that object is on the 'stack'.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC