linking problem

I am having trouble with my program that's suppose to model a periodic table.
Here is the code for my program so far. What I am trying to do is ask the user for the abbreviation of the element and base on his abbreviation my program will output the information for that given element.I have put comments on the parts that I believe are causing my problems but don't know how to go about fixing them. I will appreciate it if you guys can point me in the right direction. The error that I am getting is error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall periodic::GetAbbr(void)" (?GetAbbr@periodic@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function _main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <assert.h>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

const int MAX = 118;
class periodic
{
private:
	int m_natomic_number[1];
	double m_natomic_weight[1];
	int m_nelectron[1];
	string m_nabbr[1];
	string m_nname[1];
	//int m_nperiod;
	//int m_ngroup;
public:
	periodic() {}
	void setabbr(string x[])
	{
		m_nabbr[0] = x[0];
	}
	void setname(string x[])
	{
		m_nname[0] = x[0];
	}
	void setatomic_number(int x[])
	{
		m_natomic_number[0] = x[0];
	}
	void setatomic_weight(double x[])
	{
		m_natomic_weight[0] = x[0];
	}
	void setelectron(int x[])
	{
		m_nelectron[0] = x[0];
	}
	void showabbr();
	void showname();
	void showatomic_number();
	void showatomic_weight();
	void showelectron();
	string GetAbbr(void); //I think that is part of my problem as well as

};
void periodic::showabbr()
{
	cout << "Element abbreviation is = " << m_nabbr[0]; 
}
void periodic::showname()
{
	cout << "\nElement name is = " <<m_nname[0];
}
void periodic::showatomic_number()
{
	cout << "\nAtomic Number is = " << m_natomic_number[0];
}
void periodic::showatomic_weight()
{
	cout << "\nAtomic Weight is = " << m_natomic_weight[0];
}
void periodic::showelectron()
{
	cout << "\nElectron Number is = " << m_nelectron[0];
}
int main()
{
	string choice;
	periodic p[MAX];
	string nabbr[1],nname[1];
	int natomic_number[1],nelectron[1];
	double natomic_weight[1];
	ifstream el_abbr("E:\\elements_abbr.txt");  
	ifstream el_name("E:\\elements_name.txt");
	ifstream atomicnumber("E:\\atomic_number.txt");  
	ifstream atomicweight("E:\\atomic_weight.txt");  
	ifstream electrons("E:\\electron.txt");
	if(el_abbr.fail() || el_name.fail() || atomicnumber.fail() || atomicweight.fail() || electrons.fail())
	{
			cerr << "ERROR! FILE DID NOT OPEN!!\n";
			return 0;
	}
	for (int i=0; i<MAX; ++i)
	{
		el_abbr >> nabbr[0];
		el_name >> nname[0];
		atomicnumber >> natomic_number[0];
		atomicweight >> natomic_weight[0];
		electrons >> nelectron[0];

		p[i].setabbr(nabbr);
		p[i].setname(nname);
		p[i].setatomic_number(natomic_number);
		p[i].setatomic_weight(natomic_weight);
		p[i].setelectron(nelectron);
	}
	cout << "What element would you like to see? \n";
	cin >> choice;
	for(int i = 0; i < MAX; ++i)
	{
		{
		if (p[i].GetAbbr() == choice) //this part over here.
		p[i].showabbr();
		p[i].showname();
		p[i].showatomic_number();
		p[i].showatomic_weight();
		p[i].showelectron();
		
		cout << endl << "Press any key to continue...";
		_getch();
		return 0;
		}
	}
}
1
2
3
4
5
int m_natomic_number[1];
double m_natomic_weight[1];
int m_nelectron[1];
string m_nabbr[1];
string m_nname[1];
What?! Do you understand what declaring something as T a[1]; does? It declares a as a pointer to a static T. It's pointless, adds one unnecessary level of indirection, and should be replaced by T a;. If you do so, be sure to also change everything in this form: a[0] to this form: a

You didn't implement string periodic::GetAbbr(). That's what's causing the linker error. The linker error is pretty clear, actually. In a cryptic kind of way.
Last edited on
Yeah, I've never been a fan of the random symbols they throw in there...but usually the errors are pretty self-explanatory if you look at them...
Topic archived. No new replies allowed.