array initialization

From: Edo (edwardoJE_at_aking.com)
Date: 05/31/04


Date: Mon, 31 May 2004 12:32:20 -0700

this code is not compiling and the compile error is at the bottom of the
post. I just don't understand why it is not compiling?

using MinGW Developer Studio 2.05 with windows 2000

thanks

#include <iostream>
#include <string>
using namespace std;

class Cat {
public:
     Cat(string name = "tom", string color = "black_and_white") :
_name(name), _color(color) {}
     ~Cat() {}
     void setName(string name) {_name = name;}
     string getName() {return _name;}
     void setColor(string color) {_color = color;}
     string getColor() {return _color;}
     void speak() {cout << "meow" << endl;}
private:
     string _name;
     string _color;
};

int main()
{
     // Single Argument form of array initialization list
     Cat myCats[4] = {"Homer","Marge","Bart","Lisa"};
     return 0;
}
/*
************************************************************************
--------------------Configuration: pract - Debug--------------------
Compiling source file(s)...
aa020502a.cpp
aa020502a.cpp: In function `int main()':
aa020502a.cpp:22: error: conversion from `const char[6]' to non-scalar
type `
Cat' requested
aa020502a.cpp:22: error: conversion from `const char[6]' to non-scalar
type `
Cat' requested
aa020502a.cpp:22: error: conversion from `const char[5]' to non-scalar
type `
Cat' requested
aa020502a.cpp:22: error: conversion from `const char[5]' to non-scalar
type `
Cat' requested
aa020502a.cpp:22: warning: unused variable `Cat myCats[4]'

pract.exe - 4 error(s), 1 warning(s)
*/



Relevant Pages

  • Re: Error when compiling with g++ in Fedora Core 7
    ... Error when compiling with g++ in Fedora Core 7 ... hello.cc: In function 'int main': ... $ cat hello.cpp ...
    (Fedora)
  • Re: help with hello world
    ... >> How are you compiling it? ... > yggdrasil> cat test.cpp ... > int main ...
    (freebsd-questions)
  • Re: .login_conf ignored [solved]
    ... ; cat .login_conf ... ; uname -r ... is that you have to concatenate all sources in one run, ... confused me was that on another user's account the cap_mkdb compiling ...
    (freebsd-questions)
  • Re: Be cautious when iterating bit-shifts
    ... geo wrote: ... int main ... will result from compiling and running ... $ cat foo.c ...
    (comp.lang.c)
  • Re: Explain this
    ... At least in C and C++, the fact that we're assigning a char to x ... and C++ in a different way: in C, a character literal has type int, ... compiling it as C++ would assign to the global. ... but a language that was considerably different ...
    (comp.lang.cpp)