newbie Array

Hi,

Im trying to write a program and am having trouble linking I can link my array with char* fine but not int?
why is that it keeps saying
error C2109: subscript requires array or pointer type.
Im pretty sure it an obvious error but cant seem to find it.

I can post code if nesscary
If you are trying something like this:
1
2
int i;
i[n];
That won't work
That works for arrays, pointers or user-defined types, not for an int, did you forget a * ?
Last edited on
I thought it was the * but not sure where excatly it goes!

Do I have to star all through the previous classes that it links with or just within the question section.
If I ask through the question section I then get this error
error C2664: 'COMPUTER::COMPUTER(char *,int,float,char *,long double,float,char *,int,int,float)' : cannot convert parameter 2 from 'int *' to 'int'
Every time you are declaring a pointer you should add a * after the type
That error tells you that you are passing a int* (pointer to int) where the function takes an int.
If you want the function having an int* argument add there a *:
COMPUTER::COMPUTER(char *,int*,float,char *,long double,float,char *,int,int,float)
If you int as argument type is right, when passing the variable use the reference operator ( & )
ok, where do I use the refence operator (&)
Oops, I confused it with the deference operator ( which is another * )

1
2
3
4
void function (int);
//...
int *pointer
function( *pointer );//passes to the argument the value at the pointer location 



(reference operator the the opposite as the deference operator)



http://www.cplusplus.com/doc/tutorial/pointers.html
Last edited on
ok.

What do I do when I have a float? * using * dosn't work sais unable to convert from int to float
What is the type you are passing?
Conversion form int to float shouldn't give errors, at least a warning for possible data loss
It was cause I hadn't declared it as a float but as int changed to float and worked fine,

Also now it runs through to the program screen and after starting to input the data it sais unavaliable to initialize a varaiable.
I'm not sure I understand, what does the error message say?
Last edited on
Sorry cant remember what the message was, but I decleared it under a int then used it later as a float so I had to change what i declared as a float and not int.

I now have this problem

cout << "What specification would you like to view "; //Displays A Task title.
cin >> Z; // Stores Entered Values.
A = new (nothrow) int[Z]; //
if (A == 0) //
cout << "Error"; //
else
for (Y=0; Y<Z; Y++) //
cout << A [Y]<< ""; //

this error refers to line 3

error C2440: '=' : cannot convert from 'int *' to 'int *[10]'
'A' should be declared as int*, you seem having declared it like this:
int *A[10];. Remove [10] from there.

In the loop
1
2
for (Y=0; Y<Z; Y++)
   cout << A [Y]<< "";
You are displaying the values of 'A' without having given a value for them
Topic archived. No new replies allowed.