| | |
Dynamic arrays inside a class?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2005
Posts: 1
Reputation:
Solved Threads: 0
I think the best way for me to explain this is to show you guys what im trying to do.
I'm in school and need help trying to input data into the dynamic array thats inside a class. I made a test program that worked but use a structure inside the main function. I dont understand what i'm missing. If you guys could give me a few pointer in the general direction, certain general areas to study, it would help and a brief example but nothing in detail. Ill find those. Thanks for you time. The error i get is: error C2109: subscript requires array or pointer type
#include <iostream>
class customer
{
int CustID;
public:
void CCustRecords(int NumOfCust)
{
x = NumOfCust;
for(int i = 0; i < x; ++i)
{
cout << "Enter the Customers ID number. " << endl;
cin >> CID;
CID[i].CustID = CID;
}
}
};
void main()
{
int NumOfCust, EmployeeID;
Employee emp;
customer cust;
cout << "Welcome to the MED Recorde Managemant System" << endl;
cout << "--------------------------------------------" << endl;
cout << endl << "Authorized Personel Only" << endl;
cout << "Please Enter your Employee ID code " << endl;
cin >> EmployeeID;
if(EmployeeID == emp.EmployeeID)
{
cout << "Please enter the number of Customers you want" << endl;
cin >> NumOfCust;
cust.CCustRecords(int NumOfCust);
customer *CID = new customer[NumOfCust];
cout << endl << endl << endl;
cout << "Access Granted!" << endl;
cout << "----------------" << endl;
while(iface != 1)
{
cout << endl << "Please select one of the following" << endl;
cout << endl << "1)Creat Customer records" << endl;
cout << endl << "2)Exit Program" << endl;
int iface;
cin >> iface;
if(iface = 1)
{
cust.CCustRecords(int NumOfCust);
break;
}
else
cout << "Exiting Program" << endl;
}
delete [] CID;
}
else
cout << "I'm sorry but you entered the wrong number" << endl;
}I'm in school and need help trying to input data into the dynamic array thats inside a class. I made a test program that worked but use a structure inside the main function. I dont understand what i'm missing. If you guys could give me a few pointer in the general direction, certain general areas to study, it would help and a brief example but nothing in detail. Ill find those. Thanks for you time. The error i get is: error C2109: subscript requires array or pointer type
Here is one example of a dynamic array inside a class. From what you've shown, it looks a little inside-out; that is, it seems like you want a dynamic array of customers in main, rather than a dynamic array of whatever in a class.
C++ Syntax (Toggle Plain Text)
#include <iostream> class T { int size, *array; public: T(int mysize = 1) : size(mysize), array(new int[size]) { std::cout << "size = " << size << '\n'; } ~T() { delete[] array; } }; int main() { T a, b(5); return 0; } /* my output size = 1 size = 5 */
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- array/funtion problem, please help (C++)
- only const static integral data members can be initialized inside a class or struct (C++)
- Combined data type arrays. (C++)
- Creating dynamic arrays (C++)
- Dynamic class members? (C++)
- Class Vectorization requirements (C++)
- Huge Dynamic arrays in QB45, BC7 (Legacy and Other Languages)
- Help w/ dynamic list funtction definitions (C++)
Other Threads in the C++ Forum
- Previous Thread: cin.get issue
- Next Thread: Pleae help!!! Homework woes!
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






