Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 03-24-2008, 12:29 AM   #1 (permalink)
 
Ultra Techie

Join Date: Oct 2003

Posts: 750

slvrstang is on a distinguished road

Send a message via AIM to slvrstang
Default C++ new operator help.

Say I have two classes.

class Base

class subBase : public Base

What is happening in this line of code.

subBase *sB = new subBase();

And will this line of code compile and if yes, what is it doing?

Base *B = new subBase();
__________________

Q6600 G0 @ 3.80ghz
MCR-320-->Dtek Fuzion V2-->Dtek Fuzion GFX2-->Swiftech MCP-655-->
Asus P5K deluxe
4x1gb Crucial Ballistix @ 846mhz 5-5-5-15
8800GT
3x 250gb HDDs
Hiper 580w
Coolermaster 690 w/ water cooling mods
3dmark06 - 15,602
SuperPi 1M - 12.421s
slvrstang is offline  
Old 03-26-2008, 09:23 PM   #2 (permalink)
Baez's Avatar
 

Join Date: Sep 2005

Location: Toronto, Canada

Posts: 5,469

Baez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of light

Default Re: C++ new operator help.

In the first line you are dynamically allocating memory for a new datatype called subBase for the pointer to memory sB. You don't need the brackets on the second subBase though.

The second line will compile but there really is no point in using it. It does the same thing as the first but does not allocate any memory to store what Base has in it's class only what subBase has. Again you don't need the brackets.
__________________

Baez is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On