member array initialization
-
Hi, Can I initialize a member array of a class from the constructor
class test { int Myarray[10]; test() { } };
here I want to set the value of all elements in Myarray as 0. Is there any way to do it with out using memset()...? navedear why do You not use loop to initialize array with ur desired value. ajmalsiddiqui -- modified at 6:50 Monday 8th May, 2006
-
dear why do You not use loop to initialize array with ur desired value. ajmalsiddiqui -- modified at 6:50 Monday 8th May, 2006
-
in normal case int MyArray[10] = {0}; will initialize all the elements in that array..I just want to know is this possible in the class memebers( using initialization list ) nave
Naveen R wrote:
using initialization list
Initialization list can only be specified when an array is being declared.
Nibu thomas Software Developer Faqs by Michael dunn
-
Naveen R wrote:
using initialization list
Initialization list can only be specified when an array is being declared.
Nibu thomas Software Developer Faqs by Michael dunn
-
Initializer lists are used in a constructor to initialize members of that class. Not local variables defined inside a class.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.
-
Initializer lists are used in a constructor to initialize members of that class. Not local variables defined inside a class.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.
Ya that I know ..I tried/want to initialize a member variable not a local variable inside a function( here MyArray is a member variable ) see the class delcaration.. http://www.codeproject.com/script/comments/forums.asp?msg=1478001&forumid=1647#xx1478001xx[^] nave
-
Ya that I know ..I tried/want to initialize a member variable not a local variable inside a function( here MyArray is a member variable ) see the class delcaration.. http://www.codeproject.com/script/comments/forums.asp?msg=1478001&forumid=1647#xx1478001xx[^] nave
No, I don't think you can ust initializer lists with plain old C-Arrays. You are bound to use a loop or memset.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.