473,385 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Hi! A petty doubt before geeks!!

Hi all!

I have alittle question.
What is the code like to make sure that if we create an object of a
class dynamically , it is allocated memory but not when a static object
of the same class????

Jan 17 '07 #1
4 1113

nikki wrote:
Hi all!

I have alittle question.
What is the code like to make sure that if we create an object of a
class dynamically , it is allocated memory but not when a static object
of the same class????
Privatize the constructor and create a factory function.

Jan 17 '07 #2
nikki wrote:
What is the code like to make sure that if we create an object of a
class dynamically , it is allocated memory but not when a static
object of the same class????
Not sure what you mean here, but if you want to require the objects
of your class always created dynamically, you should provide a factory
method (which would return a pointer) and make constructors private.

I hope it's OK that I responded. I am not a geek, I just hang out
here.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 17 '07 #3
Victor Bazarov wrote:
nikki wrote:
What is the code like to make sure that if we create an object of a
class dynamically , it is allocated memory but not when a static
object of the same class????

Not sure what you mean here, but if you want to require the objects
of your class always created dynamically, you should provide a factory
method (which would return a pointer) and make constructors private.

I hope it's OK that I responded. I am not a geek, I just hang out
here.
No, you're not a geek! You're even worse! You're the C++ language
police! Aaaaah!

Jan 18 '07 #4
* nikki:
Hi all!

I have alittle question.
What is the code like to make sure that if we create an object of a
class dynamically , it is allocated memory but not when a static object
of the same class????
If you mean, "how do I ensure that objects of my class are dynamically
allocated?":

Make the destructor 'private' or 'protected', and provide an accessible
function that calls 'delete'. This can be an ordinary member function
(simple) or e.g. a friend template function (general).

This way you don't have to provide one factory function per constructor,
which is less work and better for maintenance (adding, removing or
changing constructors requires no parallell maintenance of factory
functions, and deriving from the class can be easier).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jan 18 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: EFranklin | last post by:
I am attempting to create a Petty Cash database that will ultimately print a pre-designed petty cash receipt, a report on expenditures by account number with account name, and a report which will...
20
by: rick | last post by:
Hi. I am a college kid and need some advice. I have an assignment to write about some contemporary culture for an anthropology class. Anyone know of any books about computer geek culture? thanks.
8
by: Tarique | last post by:
Hello. #include<stdio.h> int main(void) { int i=- -2; printf("%d",i); return 0; }
1
by: =?Utf-8?B?Y2Fyb2xl?= | last post by:
we have petty cash in different currencies... we used petty cash before with 3 currencies with QB - someone an idea how we could use it in the business accounting (we use microsoft accounting pro...
51
by: deepak | last post by:
Hi, For the program pasted below, scanf is not waiting for the second user input. Can someone suggest reason for this? void main() { char c;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.