0

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

Edited by Phil++: n/a

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Grn Xtrm
0

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;
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.