Hey, I'm trying to put all the objects of my class into an array so it will be easier to display.. It doesn't work though! Here is the code:

#include <cstdlib>
#include <iostream>
#include "manager.h"
#include <windows.h>
using namespace std;

void displayManagers();

int main(int argc, char *argv[])
{
    displayManagers();
    
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
void displayManagers()
{
   Manager m[1](10, "name", "name", "sfsf", 15, 45, 10);
}

main.cpp bad array initializer is the error message. Any any guys? Thanks in advanced

Recommended Answers

All 2 Replies

I don't see neither your class Manager definition, nor array 'm' def, but I guess something like that, should work:

Manager man1=(10, "name", "name", "sfsf", 15, 45, 10);
m[1]=man1;

Try reading this on array intialization
http://www.fredosaurus.com/notes-cpp/arrayptr/array-initialization.html
It seems to me that you declare the array 'm' with an inital size of 1, but are trying to add more than one element to the array. I would give a constant size to the array that will be big enough to accomodate a substantial input. Also you must set the array = to the values which must be stored in curly braces{}. Refer to the link if my explanation was unclear.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.