C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to make this snippet an efficient one?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
KK
Guest





PostPosted: Fri Nov 18, 2005 10:29 am    Post subject: How to make this snippet an efficient one? Reply with quote



Hi, The goal of this program is to define all the objects required by
the program at one place - i.e., at the time of initialization. But I
soon run into problems when an object's intilization function argument
is dependent on another object's attribute which is yet to be defined.
How can I work around this problem? Thank you.
-KK
#define SIZE 100
Class Name
{
int _pos;
int _val;
void InitObj (int pos) : _pos ( pos ) { _val = 0 ; //temporary _val
initialization } ;
void InitValue (int buffer [ SIZE ] ) { _val = buffer [ pos ] ;
//permanant _val initialization } ;
// define other essential funcs
}
class Country
{
Name obj [ 2 ] ;
obj[0].InitObj ( 1 );
/* obj[1].IntiObj(obj[0]._val); // oops! obj[0]._val is not yet
initialized to non-zero value. Is there any way to get around this
problem? */
}
void Function_That_Works(Country& ex)
{
//define buffer & other required variables here
ex.obj[ 0 ].InitValue( buffer );
ex.obj[ 1 ].InitObj( obj[0]._val ); //tedious intialization of the
obj
ex.obj[ 1 ].InitValue( buffer );
}
void Function_That_DOES_NOT_Work(Country& ex)
{
//define buffer & other required variables here
for( int i = 0 ; i < 2 ; i++ )
ex.obj[ i ].InitValue( buffer );
}


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.