Click here to Skip to main content
15,896,154 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Array Variable initialization Pin
David Crow9-Sep-08 4:35
David Crow9-Sep-08 4:35 
GeneralRe: Array Variable initialization Pin
CPallini9-Sep-08 5:18
mveCPallini9-Sep-08 5:18 
GeneralRe: Array Variable initialization Pin
David Crow9-Sep-08 5:21
David Crow9-Sep-08 5:21 
GeneralRe: Array Variable initialization Pin
CPallini9-Sep-08 5:30
mveCPallini9-Sep-08 5:30 
GeneralRe: Array Variable initialization Pin
toxcct9-Sep-08 5:42
toxcct9-Sep-08 5:42 
GeneralRe: Array Variable initialization Pin
CPallini9-Sep-08 6:01
mveCPallini9-Sep-08 6:01 
GeneralRe: Array Variable initialization Pin
David Crow9-Sep-08 6:04
David Crow9-Sep-08 6:04 
GeneralRe: Array Variable initialization Pin
CPallini9-Sep-08 9:26
mveCPallini9-Sep-08 9:26 
DavidCrow wrote:
0 works fine.


It is just a side-effect of default (int) initialization: you're actually initializing only the first array item. Try the following code:
#include <iostream>
using namespace std;

struct MyStruct
{
  MyStruct():_i(-1), _j(0),_k(-1){ }
  MyStruct(int a):_i(a), _j(a), _k(a){ }
  int _i,_j,_k;
};



void main()
{
  int i;
  MyStruct a[5] = {0};
  for (i=0; i<5; i++)
  {
    cout << i << ") {" << a[i]._i << ", " << a[i]._j  <<", " << a[i]._k << "}" << endl;
  }
}	



DavidCrow wrote:
This is why I only do it when setting things to 0. I use memset() otherwise.

The above is a wise approach.
Smile | :)

If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.

This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke

[My articles]

GeneralRe: Array Variable initialization Pin
David Crow9-Sep-08 10:16
David Crow9-Sep-08 10:16 
GeneralRe: Array Variable initialization Pin
CPallini9-Sep-08 10:24
mveCPallini9-Sep-08 10:24 
AnswerRe: Array Variable initialization Pin
laksh22049-Sep-08 2:48
laksh22049-Sep-08 2:48 
GeneralRe: Array Variable initialization Pin
T.RATHA KRISHNAN9-Sep-08 2:56
T.RATHA KRISHNAN9-Sep-08 2:56 
Questionhelp on using asynchronous sockets in windows using multiple threads Pin
mohant$.net9-Sep-08 2:26
mohant$.net9-Sep-08 2:26 
AnswerRe: help on using asynchronous sockets in windows using multiple threads Pin
cmk9-Sep-08 3:12
cmk9-Sep-08 3:12 
QuestionHow to reslove warning LNK4098: defaultlib "MSVCRTD", LNK4098, LNK4098 Pin
ptr_Electron9-Sep-08 2:23
ptr_Electron9-Sep-08 2:23 
AnswerRe: How to reslove warning LNK4098: defaultlib "MSVCRTD", LNK4098, LNK4098 Pin
sashoalm9-Sep-08 5:27
sashoalm9-Sep-08 5:27 
Questionexecute .bat file Pin
Madan Chauhan9-Sep-08 1:46
Madan Chauhan9-Sep-08 1:46 
QuestionRe: execute .bat file Pin
Rajesh R Subramanian9-Sep-08 1:56
professionalRajesh R Subramanian9-Sep-08 1:56 
AnswerRe: execute .bat file Pin
Madan Chauhan9-Sep-08 2:01
Madan Chauhan9-Sep-08 2:01 
GeneralRe: execute .bat file Pin
Rajesh R Subramanian9-Sep-08 2:09
professionalRajesh R Subramanian9-Sep-08 2:09 
JokeRe: execute .bat file Pin
toxcct9-Sep-08 2:12
toxcct9-Sep-08 2:12 
AnswerRe: execute .bat file Pin
toxcct9-Sep-08 1:58
toxcct9-Sep-08 1:58 
GeneralRe: execute .bat file Pin
Madan Chauhan9-Sep-08 2:04
Madan Chauhan9-Sep-08 2:04 
GeneralRe: execute .bat file Pin
toxcct9-Sep-08 2:08
toxcct9-Sep-08 2:08 
GeneralRe: execute .bat file Pin
Madan Chauhan9-Sep-08 2:22
Madan Chauhan9-Sep-08 2:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.