What am I doing wrong

This is my first time asking the internetz for programming help, so bear with me. I have looked around for a while but cannot find a solution to my problem.

Problem: I cannot get past the following error: error C2059: syntax error : ']'

header file:
#ifndef INVENTORY_H
#define INVENTORY_H

#include <iostream>
#include <iomanip>

class Inventory {
public:
// Default constructor
Inventory();

//
//
//

//Secondary constructor
Inventory(int prodID, char prodDescript[], int manuID, double wholesalePrice,
double markupPercentage, int inventoryQuanity);

private:
int prdID;
char prdDescript[50];
int manID;
double wholesale;
double markup;
int quanity;

};

implementation file:
#include "inventory.h"
#include <iomanip>
#include <iostream>

using namespace std;

Inventory::Inventory()
{
prdID = 0;
prdDescript[] = "NULL";
manID = 0;
wholesale = 0;
markup = 0;
quanity = 0;
}

#endif

I was trying to check my faults as I went. The rest of the intended program is a breeze but I am stuck on the character array. I have made many many programs before but have never had to include a character array in a class. Help?
Last edited on
You can't really assign to a char array like that.

What you're trying to do would be done like this:

strcpy(prdDescript, "NULL");
(which is in the <cstring> library)

However more standard approaches would be:

prdDescript[0] = 0;
prdDescript[0] = '\0';

It appears you're using it as text, so why not use a string? That way, you can have things like

prdDescript = "NULL";
Thanks for your response.

As far as using a string, that's what I would rather use but this project requires the use of a character array.

The way I have the code above was meant for "NULL" to be used within the default construct. But even though I gave it a size of 50, it will not let me put "NULL" or anything for that matter into the array, which is why I am confused.
In the class declaration you can only say what members are present, you can't give them any values yet - this is what you do in the constructor.

So in this case, you would need to use the strcpy function.
Topic archived. No new replies allowed.