i'm trying to read a file into an array struct using a function, i get the errors:

1.error LNK2019: unresolved external symbol "void __cdecl loadarray(struct ElementType * const,int)" (?loadarray@@YAXQAUElementType@@H@Z) referenced in function _main

2.fatal error LNK1120: 1 unresolved externals

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

ifstream fin;

int i =0;

struct ElementType
{
string Name;
int atomicnumber;
double atomicmass;
double density;
}r1,r2,r3;

void loadarray(ElementType A[],int nItems);

const int maxsize = 15;

ElementType E[15];

int main()
{
fin.open("element.dat");

loadarray(E,1);

return 0;
}

void loadarray(ElementType A[],int& nItems)
{
	while(!fin)
	{
	
	fin>>A[i].Name;
	fin>>A[i].atomicmass;
	fin>>A[i].atomicnumber;
	fin>>A[i].density;
	i++;

	}
}

Edited 6 Years Ago by WaltP: Fixed CODE Tags

i'm trying to read a file into an array struct using a function, i get the errors:

1.error LNK2019: unresolved external symbol "void __cdecl loadarray(struct ElementType * const,int)" (?loadarray@@YAXQAUElementType@@H@Z) referenced in function _main

2.fatal error LNK1120: 1 unresolved externals

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

ifstream fin;

int i =0;

struct ElementType
{
string Name;
int atomicnumber;
double atomicmass;
double density;
}r1,r2,r3;

void loadarray(ElementType A[],int nItems);

const int maxsize = 15;

ElementType E[15];

int main()
{
fin.open("element.dat");

loadarray(E,1);

return 0;
}

void loadarray(ElementType A[],int& nItems)
{
while(!fin)
{

fin>>A[i].Name;
fin>>A[i].atomicmass;
fin>>A[i].atomicnumber;
fin>>A[i].density;
i++;

}
}

Edited 6 Years Ago by WaltP: Fixed CODE Tags again!

Close on the tags:

[code]
// code here
[/code]

The closing tag needs to have a slash. You still have time to edit your last post. Stick it in there and the code will show with line numbers, syntax highlighting, etc.

Thanks.

Prototype and Function definition parameters donot match. Change the function definitions second argument to a pass by value and not pass by reference. And i think it will have no problem compiling

And Yeah, the next time you post code.. please make sure that you use the code tags properly. Proper code tags lead to faster and better answers :)

Edited 6 Years Ago by Sky Diploma: n/a

This article has been dead for over six months. Start a new discussion instead.