Little help with an object that accepts an array

#include <iostream>
using namespace std;

class Manager1
{
Manager1(string M[5]);
void setEmployeeInfo(string [5]);
string getEmployeeInfo() const;

private:
string emp1;
string emp2;
string emp3;
string emp4;
string emp5;
string Manager[5];
int numberOfEmployees;



};
Manager1::Manager1(string M[5])
{


}
void Manager1::setEmployeeInfo(string M[5] )
{
M[5];
M[0] = emp1;
M[1] = emp2;
M[2] = emp3;
M[3] = emp4;
M[4] = emp5;
}

string Manager1::getEmployeeInfo() const
{
for(int i =0; i <5; i++)
{
return Manager[i];
}
}

int main()
{

string a[5] = {"j","j","j","j","j"};
Manager1 Manager(a[5]);


}
Can anyone tell me what to do??
Thank you very much!
First, edit your post to add code tags and intuitive indentation.
See: http://www.cplusplus.com/articles/jEywvCM9/

Can anyone tell me what to do??

... to do about what?
What problems do you have with the code?
Which operations you are unsure about?

Yes, you do have both logical and syntax errors. The compiler should point out the latter ones. What does it say?
1
2
string a[5] = {"j","j","j","j","j"};
Manager1 Manager(a[5]);


So a[5] in the second line of the above refers to only the sixth element of the array. That's neither the entire array, nor is it in-bounds. Notice that there's only five elements in a. (a[0] is the first element :))

You should pass just the name of the array to the constructor. Note that the size of the array is lost when the constructor receives it.

The line Manager1 Manager(...) says you're creating a new Manager1 called Manager. Perhaps it should be the other way around?
Last edited on
Topic archived. No new replies allowed.