array initialization
From: Edo (edwardoJE_at_aking.com)
Date: 05/31/04
- Next message: David White: "Re: array initialization"
- Previous message: Marlene Stebbins: "Re: [C][OT] freeing memory allocated in a function"
- Next in thread: David White: "Re: array initialization"
- Reply: David White: "Re: array initialization"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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)
*/
- Next message: David White: "Re: array initialization"
- Previous message: Marlene Stebbins: "Re: [C][OT] freeing memory allocated in a function"
- Next in thread: David White: "Re: array initialization"
- Reply: David White: "Re: array initialization"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|