undefined reference

I need help, because this is giving me an undefined reference to my class.

DNA.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef DNA_H
#define DNA_H
#include <string>
using namespace std;

class DNA{
	private:
		string dnaString;
		
	public:
		DNA(string dna);
		DNA(); // default constructor
		string changeString(string dna);
};

#endif 


DNA.cpp
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
#include <iostream>
#include "DNA.H"
#include <string>
using namespace std;

DNA::DNA(string dna)
	{
		dnaString = dna;
	}
	
DNA::DNA()
	{
		dnaString = " ";
	}
	
string DNA::changeString(string dna)
{
		string newString;
		
		for(int i = 0; i < dna.length(); i++)
		{
			if(dna[i] == 'G')
				dna[i] = 'C';
			else if(dna[i] == 'T')
				dna[i] = 'A';
			else if(dna[i] == 'C')
				dna[i] = 'G';
			else if (dna[i] == 'A')
				dna[i] = 'T';
				
			newString += dna[i]; 
		}	
		return newString;
}


main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include "DNA.H"
#include <string>
using namespace std;

int main()
{
	
	DNA aDNA("GTATCCAATGCC");
	
	cout << aDNA.changeString("GTATCCAATGCC");
	
	
	
	system("pause");
	return 0;
}

Last edited on
closed account (48T7M4Gy)
Your code runs OK as a single file so what is the full/complete error message and error reference number?
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
#include <iostream>
#include <string>

using namespace std;

class DNA{
private:
    string dnaString;
public:
		DNA(string dna);
		DNA(); // default constructor
		string changeString(string dna);
};

DNA::DNA(string dna)
	{
		dnaString = dna;
	}
	
DNA::DNA()
	{
		dnaString = " ";
	}
	
string DNA::changeString(string dna)
{
		string newString;
		
		for(int i = 0; i < dna.length(); i++)
		{
			if(dna[i] == 'G')
				dna[i] = 'C';
			else if(dna[i] == 'T')
				dna[i] = 'A';
			else if(dna[i] == 'C')
				dna[i] = 'G';
			else if (dna[i] == 'A')
				dna[i] = 'T';
				
			newString += dna[i]; 
		}	
		return newString;
}

int main()
{
    DNA aDNA("GTATCCAATGCC");
    cout << aDNA.changeString("GTATCCAATGCC");
	return 0;
}
Last edited on
I figured the problem is "DNA.H" and switch it to "DNA.h". There's also a problem with undefined reference to WinMain, which doesn't allow me to create this project with classes.
closed account (E0p9LyTq)
Using Visual Studio 2015 your header/source files setup works. Maybe you should rebuild? Sometimes errors can creep in when making changes and object files aren't updated.
closed account (E0p9LyTq)
There's also a problem with undefined reference to WinMain, which doesn't allow me to create this project with classes.


Are you using Visual Studio? If you are you need to create your project as a Win32 console application, not Win32 project.

WinMain() is an application's entry point for a Windows GUI app, not main(). main() is for a console app.
closed account (48T7M4Gy)
so what is the full/complete error message and error reference number?


And, the answer is ... or have you solved it so this thread is green ticked??
personxd1,

Just a thought here if you are using Visual Studio as I do you need to include the #include "stdax.h" file in each .cpp file. Once I put that include in the "DNA.cpp" file it compiled correctly. Just a thought and the program appeared to run OK.

Andy
Topic archived. No new replies allowed.