hi all,

i have created a class names members which looks like this..

class mymembers{
  int data;
  float dummy;
  char* thename;
  public :
         mymembers()
         {
         cout<<"the value of i is "<<data;
        data =12;
         }
  mymembers(int ic,char* name)
  {
              thename = name;
              data= ic;
             cout<<"hello this object's data value is "<<data<<endl; 
              }
     mymembers(int ic,int it)
  {
              dummy = 12;
              data= ic;
             cout<<"hello this object's data value is "<<data<<endl; 
              }


  };

in main i'm initializing an array of 3 objects
the code looks like this...

int main()
{
 mymembers m[3] = {(20,22),(21,33),(45,44)};

    getch();

}

and i get an error
57 C:\Documents and Settings\abhishek\My Documents\check.cpp conversion from 'int' to non-scalar type 'mymembers' requested

and if i use one argument constructor to intialize the objects in the array then it shows no problem...so why its not taking the second argument correctly..which conversion it's talking abt...plz help!!!

Edited 3 Years Ago by pritaeas: Fixed formatting

Please post using code tags :) ...
> Change mymembers m[3] = {(20,22),(21,33),(45,44)}; (in your main)
to mymembers m[3] = {mymembers(20,22),mymembers(21,33),mymembers(45,44)}; > Edit:: Look at this ...

Another defects:
1. the default (the 1st) ctor does not initialize dummy and thename members.
2. the 2nd ctor does not initialize dummy member. It saves a simple pointer to the 2nd arg (especially dangerous)
3. the 3rd ctor does not initialize name member (especially dangerous case). Can't get literal names (char* instead of const char* ).
4. mymembers(x,0) ctor calls are ambiguous w/o explicit cast.
5. No copy ctor and assignment overloading for the class with pointer members (as usually it's a very dangerous symptom).

Difficult class confinement ;)...

This article has been dead for over six months. Start a new discussion instead.