473,396 Members | 2,011 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,396 software developers and data experts.

is this correct??

2
In test.hpp
...
..
typedef struct _test_
{
...
...
} test
class test
{
...
private:
static test* infoP_m;
...
};

in test.cpp file
...
...
//static member initialization
test* infoP_m = 0;

//constructor
test::test()
{
memset(&infoP_m,0,sizeof(infoP_m); // Is this correct
...
}

do I need to instancitate the infoP_m structure (to allocate memory, or it is already allocated ??)
thanks
-pkm
Nov 20 '06 #1
2 1287
Banfa
9,065 Expert Mod 8TB
This
Expand|Select|Wrap|Line Numbers
  1. typedef struct _test_
  2. {
  3. ...
  4. ...
  5. } test
  6.  
can be this (note the added ; )
Expand|Select|Wrap|Line Numbers
  1. struct test
  2. {
  3. ...
  4. ...
  5. };
  6.  
This
Expand|Select|Wrap|Line Numbers
  1. class test
  2. {
  3. ...
  4. private:
  5.     static test* infoP_m;
  6. ...
  7. };
  8.  
should have a non-conflicting name like this
Expand|Select|Wrap|Line Numbers
  1. class ctest
  2. {
  3. ...
  4. private:
  5. static test* infoP_m;
  6. ...
  7. };
  8.  
This
Expand|Select|Wrap|Line Numbers
  1. //static member initialization
  2. test* infoP_m = 0;
  3.  
should be this (otherwise you have just declared a global pointer not a static class member)
Expand|Select|Wrap|Line Numbers
  1. //static member initialization
  2. test *ctest::infoP_m = 0;
  3.  
This
Expand|Select|Wrap|Line Numbers
  1. //constructor
  2. ctest::ctest()
  3. {
  4.     memset(&infoP_m,0,sizeof(infoP_m); // Is this correct
  5. ...
  6. }
  7.  
Is poor style, every time you construct a class of type ctest you set the pointer to NULL, also it can be written more clearly as
Expand|Select|Wrap|Line Numbers
  1. //constructor
  2. ctest::ctest()
  3. {
  4.     infoP_m = 0; // Is this correct
  5. ...
  6. }
  7.  
do I need to instancitate the infoP_m structure (to allocate memory, or it is already allocated ??)
There is no infoP_m structure, it is a pointer and yes you do need to allocate memory to that pointer before you try and use what it points to.
Nov 21 '06 #2
pkm
2
that was very helpful..thank you..
Regards
-Pkm
Nov 21 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: David Opstad | last post by:
I have a question about text rendering I'm hoping someone here can answer. Is there a way of doing linguistically correct rendering of Unicode strings in Python? In simple cases like Latin or...
0
by: Sarah Tegtmeier | last post by:
Hi I have a question about the correct use of the attribute xsi:schemaLocation. My programm has to process XML files where the value of this attribute causes some problems. The programm is...
1
by: Richard Golebiowski | last post by:
I have been trying to figure this out for quite some time and cannot find any examples in VB.Net or in VB that work correctly. I am working on an application where I want the user to be able to...
14
by: john.burton.email | last post by:
I've done some extensive searching and can't seem to find an answer to this - Is it correct to using "using" with templates, for example: using std::vector; Or do I need to specify the type...
6
by: Rob Thorpe | last post by:
Given the code:- r = sscanf (s, "%lf", x); What is the correct output if the string s is simply "-" ? If "-" is considered the beginning of a number, that has been cut-short then the...
5
by: blackg | last post by:
Input string not in correct format -------------------------------------------------------------------------------- I am trying to view a picture from a table. I am getting this error Input string...
2
by: thisis | last post by:
Hi All, I need the PUBS.mdb for pulling images: PUBS.mdb must have the table: pub_info tbl_pub_info : has 3 fields Data_Type : ok Data_Type : ok
0
by: sehguh | last post by:
Hiya Folks, I am Currently using windows xp. Also using Visual Web Developer 2005 and Microsoft Sql server 2005. The main page consists of an aspx page and a master page. The page also...
3
lee123
by: lee123 | last post by:
I have a problem getting the correct to count +1 every time I get an answer right and the incorrect is the same. I have two lbl's named number1 and number2 which produces a Rnd# in each lbl. ...
10
by: onetruelove | last post by:
I want to creat a post like this blog: http://onlinetoefltest.blogspot.com/2007/08/level-c-lesson-1.html When you chose all the answers and click show answer a msg box will appear and tells how...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.