hi Guys!
I am having a class, having around 300+ pointers ONLY, I need to set
them all NULL, when the object is created.
The best way I think is
memset(this, NULL, sizeof(classnam e));
whats your suggestion??
Will this break anything?? as it is done in constructor??
any suggestions??? 16 10529
Also guys what do you all suggest about deleting?? as this class is
only going to have Pointers as member variable,
hack_tick wrote: hi Guys!
I am having a class, having around 300+ pointers ONLY, I need to set them all NULL, when the object is created.
The best way I think is
memset(this, NULL, sizeof(classnam e));
whats your suggestion?? Will this break anything?? as it is done in constructor??
any suggestions???
hack_tick wrote: hi Guys!
I am having a class, having around 300+ pointers ONLY, I need to set them all NULL, when the object is created.
The best way I think is
memset(this, NULL, sizeof(classnam e));
This will turn the virtual fn pointer of your object to NULL. whats your suggestion?? Will this break anything?? as it is done in constructor??
any suggestions???
hack_tick wrote: hi Guys!
I am having a class, having around 300+ pointers ONLY, I need to set them all NULL, when the object is created.
The best way I think is
memset(this, NULL, sizeof(classnam e));
whats your suggestion?? Will this break anything?? as it is done in constructor??
any suggestions???
You have at least two things to be concern.
1. Have you derived this class from anyclass?
If yes, but you might say that there isn't any data member in Base
class (please read 2)
2. Is there any virtual method inside this class?
hack_tick wrote: hi Guys!
I am having a class, having around 300+ pointers ONLY, I need to set them all NULL, when the object is created.
The best way I think is
memset(this, NULL, sizeof(classnam e));
whats your suggestion?? Will this break anything?? as it is done in constructor??
any suggestions???
Sounds like you got a blob on your hands. Factor it and make it more
maintainable. When you think, "I would like to memset because this
thing has too many damn variables," it is time to rethink your design.
hi
Prawit Chaivong wrote:
[....] You have at least two things to be concern. 1. Have you derived this class from anyclass? If yes, but you might say that there isn't any data member in Base class (please read 2)
nope!!
2. Is there any virtual method inside this class?
nope
The class is not meant to be derived, it is just meant to handle all
those global variables into one namespace with heap control, so whats
your suggestion??
hi,
Noah Roberts wrote:
[...] Sounds like you got a blob on your hands. Factor it and make it more maintainable. When you think, "I would like to memset because this thing has too many damn variables," it is time to rethink your design.
Actually I am porting existing app, to Symbian, which require me to
move all the global variables to Thread Local Storage (TLS), by making
them member to a class, as Symbian does not support Global Variables,
on some of the OS versions.
hack_tick wrote: I am having a class, having around 300+ pointers ONLY, I need to set them all NULL, when the object is created.
The best way I think is
memset(this, NULL, sizeof(classnam e));
1) won't set pointers to NULL (will set them to all bits zero, which
might be different)
2) might roach other parts of your object (eg. a vtable).
If your question is "does this work in MSVC on windows XP"
then ask in some other newsgroup.
To initialize them properly then you should store all your pointers
in a container that will initialize all of its members, eg:
struct Foo
{
std::vector<T *> pointers;
Foo(): pointers(300, 0) {}
}
You could use a map<string, T *> if you want to refer to them by name.
* hack_tick: hi,
Noah Roberts wrote: [...]
Sounds like you got a blob on your hands. Factor it and make it more maintainable. When you think, "I would like to memset because this thing has too many damn variables," it is time to rethink your design.
Actually I am porting existing app, to Symbian, which require me to move all the global variables to Thread Local Storage (TLS), by making them member to a class, as Symbian does not support Global Variables, on some of the OS versions.
/One/ global variable is one too many.
And you have 300...
Anyways, default initialization (or per C++2003, value initialization)
will do the trick.
struct PODPointers
{
void* myGlobalPointer 1;
void* myGlobalPointer 2;
};
struct Pointers: PODPointers
{
Pointers(): PODPointers() {}
};
--
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?
hack_tick <sh************ @gmail.com> wrote: The class is not meant to be derived, it is just meant to handle all those global variables into one namespace with heap control, so whats your suggestion??
What do you mean by "with heap control"?
If they are just a bunch of global variables, and you are
not creating multiple objects of this class, consider just
making them variables in a namespace and don't use a class.
Then they can be initialized statically, which cost nothing
in runtime.
Steve This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Manoj |
last post by:
Hi ,
I have written a simple program usinga class.
But it not compiling.The error i get is
my = myclass("Paul", "John")
TypeError: this constructor takes no arguments
I checked some previous posting.I have given two underscores
for the constructor it.
Any ideas ?
|
by: John Haigh |
last post by:
Should possibly have an "add" method in a PostingObject class in the
constructor of PostingObject. will call to add a Posting to the ? Does this
make sense? My sense is that a PostingObject needs a Posting, so would I do
this in the PostingObject Constructor?
Here is my code:
using System;
using System.Collections;
using...
|
by: murat oguzalp |
last post by:
i want to call base and this constructor at the same time. is is possible?
i mean:
B(int a, int b, int c):base(a):this(b)
{
// do something with c
}
at java i used to do that:
|
by: Henry |
last post by:
I was trying to derive a class from System.Windows.Forms.ComboBox. My goal was to create a class that loaded its own data. I did not want to create too many objects, so I tried to share a Database object from the calling class, but the compliler doesn't like it when I try to provide and overrided contructor. See the code below:
Do I have to...
|
by: pat |
last post by:
Hi, I have been asked for an exam question to implement the
constructor, copy constructor and destructor for the following class
that describes an n-by-n matrix containing n squared integer values.
(Eg. a matrix of n rows and n colums):
import <iostream.h>
class myMatrix
{
| |
by: DaTurk |
last post by:
Hi,
I was wondering if there is a CLI equivalent to using the this keyword
to overload constructors. You know where you would do something like
MyClass() : this("something")
{
}
|
by: python101 |
last post by:
class double:
def __ini__(self,x1,y2):
self._x=x1
self._y=y2
def result(self):
return (self._x)*(self._y)
def x2(self):
return 2*self._result()
|
by: Samishii23 |
last post by:
So I have a user login system. The login works.
What I want to do is make a variable array in the class available for general usage. Obviously in most cases set the data in the constructor.
My login / user class has the login stuff within it, as well as the user functions. In this class I have {bool LoggedIn()} that I use for login status...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |