0

Here is my struct (It is in private section of Data-structure class):

 private:
 // this is the main node pointer array to keep
 // track of buckets and its chain.
    struct Node {

  /** member variables */
  unsigned int iCID;
  std::string sVoting_PN;
  std::string sTS[T_LITTRAL];
  unsigned int iCounter[12] = {0};


  /** constructor initializes */
  Node(unsigned int CID, std::string PN, std::string TS, unsigned int counter, unsigned int index ) {
    this->iCID = CID;
    this->sVoting_PN = PN;
    this->sTS[index] = TS;
    this->iCounter[CID] = iCounter[CID] + counter;
}

Node *next;
};
Node* nodeArray[TABLE_SIZE];

I want to initialize all the values of iCounter array to 0. how do i do that?

I tried this one

  unsigned int iCounter[12] = {0};

but it gives me warning, that i have to remove anyhow! Any idea or help is greatly appreciated guys. Thanks in advance.

Mohan Kumar P
  • 3,122
  • 1
  • 14
  • 17
Abu Shumon
  • 1,834
  • 22
  • 36
  • 3
    What warning specifically do you get? I get none [in this reduced test](http://liveworkspace.org/code/e6e5a598130d40a3ac6a8c0322a3e219) (assuming that's where you actually put the `= {0}`). – Xeo Nov 04 '12 at 03:50
  • @Xeo, here the warnigs are ############################################## warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default] warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default] – Abu Shumon Nov 04 '12 at 12:09
  • Well, why don't you just include... `-std=c++11` when compiling the code? – Xeo Nov 04 '12 at 13:02
  • I dont know how to include '-std=c++11'. could u please suggest me. and by the way, i am compiling it in my university compiler. – Abu Shumon Nov 04 '12 at 13:10
  • Okay, how exactly do you compile your code? If you use the command line, and assuming you're using GCC/g++, `g++ -std=c++11 your_files.cpp and the other flags`. For anything else, there's too little information to tell (i.e., *what* is your university's compiler / IDE). – Xeo Nov 04 '12 at 14:57
  • thanks a lot for your support Xeo. it worked the way u told. But i had to change my struct constructor due to some other constraints. Finally happy running. I am adding that modified one to the answer section. – Abu Shumon Nov 04 '12 at 21:23

1 Answers1

0

It worked the other way round. the following line was the problem.

unsigned int iCounter[12] = {0};

After a lot of different tries, finally i got this way of initializing works fine without any warning and error. I am adding this to the answer part, so that someone else having similar problem might get help from this.

struct Node {
Node(): iCID(0), sVoting_PN("") {

  for(unsigned int l=0;l<T_LITTRAL;l++){

    sTS[l]="";
    if(l<AMOUNT_OF_ARTISTS){
      iCounter[l]=0;
    }
  }

}

  //member variables 
  unsigned int iCID;
  std::string sVoting_PN;
  std::string sTS[T_LITTRAL];
  unsigned int iCounter[AMOUNT_OF_ARTISTS]; 

  Node *next;
};
Abu Shumon
  • 1,834
  • 22
  • 36