<unresolved overloaded function type>[int]’ for array subscript Error Message

I'm writing a program to read a file that contains information about molecules and extra the x,y,z coordinates of atoms in the molecule, and the atom type. This particular molecule has 13 atoms. After extracting the xyz data, I want to calculate the distances between atoms in the molecule and store them in a 13 x 13 array. However, during compilation, this error keeps showing up and I don't know why. Help?


#include <iostream>
#include <string>
#include <fstream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main ()
{
 struct xyzA {
 float xx;
 float yy;
 float zz;
 string A;
 			  };

//making a 13 element array filled with xyzA structures
  xyzA compact [13];

 string line;
 ifstream myfile ("1mol_test.sdf");
 	if (myfile.is_open())
	 {
	        int nn = 0;
		while (!myfile.eof())
			{
				xyzA data;
//extracts the first thing to x, the 2nd thing to y, the 3rd thing to z and changes the type

		 		myfile >> data.xx >> data.yy >> data.zz >> data.A;
				if (myfile.eof())
				break;
				compact[nn] = data;
				cout << "n = " << nn << endl;
				nn += 1;
//this just grabs the rest of the line of 0s and does nothing with it
				getline (myfile, line);
		
				cout << "atom:" << data.A <<" x:" << data.xx << " y:" << data.yy << " z:" << data.zz << endl;
				cout << "putting this data into the array..." << endl;
	    		};
		myfile.close();
	}

cout << "Now I will display what I have stored in my array!" << endl;
for (int n=0; n<13; n++) {
cout << "x:" << compact[n].xx << " y:" << compact[n].yy << " z:" << compact[n].zz << " atom:" << compact[n].A << endl;
			 }

float distances [13][13];
for (int i=0; i<13; i++)
	{
	cout << "i = " << i << endl;
	for (int j=0; j<13; j++)
		{
		cout << "j = " << j << endl;
		double deltax, deltay, deltaz;
		deltax = (compact[i].xx - compact[j].xx)*(compact[i].xx - compact[j].xx);
		deltay = (compact[i].yy - compact[j].yy)*(compact[i].yy - compact[j].yy);
		deltaz = (compact[i].zz - compact[j].zz)*(compact[i].zz - compact[j].zz);
		distance[i][j] = sqrt(deltax + deltay + deltaz);
		cout << "The distance between atom " << i << " and atom " << j << " is " << distance[i][j] << endl;
		}
	}
  return 0;
}


Read_1mol.cpp: In function ‘int main()’:
Read_1mol.cpp:64: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
Read_1mol.cpp:65: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
It seems that you did not close the definition of the structure

struct xyzA {
float xx;
float yy;
float zz;
string A;


Where does it end?
Where does it end?

... on the next line.

I believe:

distance[i][j] = sqrt(deltax + deltay + deltaz);

should be:

distances[i][j] = sqrt(deltax + deltay + deltaz);

You would've gotten a more informative error message if you hadn't done:

using namespace std;

And brought std::distance into the global namespace.
Last edited on

cire (881)

Where does it end?


... on the next line.


Ha-ha! The code is so bad formated that I had not seen the closing brace.:)
Heheh. It was oddly placed.
Topic archived. No new replies allowed.