![]() |
|
#1
|
|||
|
|||
Concept of new operatorHi All,
I have some queries regarding the new operator. Can any one clearify them to me ? 1) As far as i know new is an operator which calls the constructor and allocates the memory using sizeof() operator. But, sizeof operator is an operator that is executed during preprocessing time and constructor is a function that should be called during execution time. This means that new is able to handle both pre processing execution and run time execution ? 2) We use new operator to call the constructor. but, we can also allocate memory as below char *c = new char; In this case there is no concept of constructor being called. Then how the new operator works? 3) If we declare function as a static function that function can be called and defined only in that particular file itself. But, how the compiler can achieve this ? Thanks and Regards Vikram |
|||
|
#2
|
|||
|
|||
Re: Concept of new operatorQuote:
Of course, the allocation is done in run time. Quote:
How it works depends on compiler and OS, and its implementation. Anyway, I don't know how it's implemented Quote:
Do not confuse them with static methods defined in a class. They has different meaning: They're class methods and not object methods. Regards __________________
Please, correct me if I'm wrong, and sorry for my english ;) |
|
#3
|
|||
|
|||
Re: Concept of new operatorHi,
I had some other thought... Seems like the explaination provided by mamntc02 is correct but i like to add more to it... any corrections are accepted. For 1 and 2 point On trying to instantiate an object both in the case of user defined or default one.. it first checks if the operator new is been overloaded by it's class or not, if not it will go to the global scope and fetches the size of the object to be created.Allocation of the memory takes place later, in the case of the char may be in the global scope the size of char is be defined just as in C complier. For point 3 If we declare function as a static function that function can be called and defined only in that particular file itself. But, how the compiler can achieve this ? the techinques may be of name mangalining(prefix the function name with the file name along with the parameters to the function, during parsing inside the complier) along with the location where this static method or the variable are been stored.. usually in bss.. Thereby the can be easily distinguisable . |
|
#4
|
|||
|
|||
Re: Concept of new operatorA billion thnaks for your help.
|
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Assignment Operator and Pointer | Peter_APIIT | C++ Forum | 14 | 25-Sep-2007 06:36 |
| Write a C++ program involving operator overloading | jjrsbigo | C++ Forum | 2 | 13-Dec-2006 07:47 |
| C++ PhoneBook | marita | C++ Forum | 46 | 12-Jun-2005 13:10 |
| Operator overloading c++ | clander | C++ Forum | 4 | 25-Apr-2005 10:21 |
| Operator overloading problem | grscot | C++ Forum | 2 | 21-Oct-2004 00:59 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The