yes,but..

michael michael8110 at terra.com.br
Mon Aug 9 21:12:25 PDT 2004


Thanks,guys,now
#include<iostream>
  using namespace std;
  class car
  {public:
  car();
  char itsName[20];
  car(char * a)
  { strcpy(itsName, a); }
  };
  int main()
  {car citroen("DS19");
   cout<<citroen.itsName<<"\n";
  return 0;
  }
and

#include<string>
#include<iostream>
  using namespace std;
  class car
  {public:
  string itsName;
  car(string a)
  {itsName=a;}
  };

  int main()
  {car citroen("DS19");
  cout<<citroen.itsName<<"\n";
  return 0;
  }

do exactly the same thing,but  still i'd like to mention what was at the  
origin of all this,namely what this code produces:
#include<iostream>
using namespace std;
int main()
{int arr[3]={1,2};
cout <<arr<<"\n";
char ar[3]={'b','y'};
cout <<ar<<"\n";/*you are still trying to use a char *
(memory address) as a value to assign to an array, which is NOT allowed
in C.*/
return 0;
}
which is
   michael ~ # ./a.out
0xbffff750
by
  so,after all ar is not an char* but a char[] ,(although arr is an int*  
)at least as seen by the compiler.Strange,isn't it?Maybe i'm making a  
salad out of it all,anyway,at least now it works :-)


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/



More information about the lfs-chat mailing list