Unresolved Externals, project not finding associated .cpp file

Fairly new to C++, but familiar with programming to a decent degree. According to the instructions, I've separated the declarations and definitions of my methods into a header file and source file respectively. I'm trying to have another source file access the methods. I've included the header in both of the source files, so they should have access to each other if I'm understanding how it works correctly. However, running the program gives me several unresolved external symbol errors. The code is as follows.

Header file
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
  #ifndef SELLER_H
#define SELLER_H


//*****************************************************************
// FILE:      Seller.h
// AUTHOR:    your name
// LOGON ID:  your z-ID
// DUE DATE:  due date of assignment
// 
// PURPOSE:   Contains the declaration for the Seller class.
//*****************************************************************

class Seller
{
	// Data members and method prototypes for the Seller class go here
	public:
		static char name[31];
		static double total;
	
		Seller::Seller();
		Seller::Seller(char nameArray[], double salesTotal);
		char* getName();
		double getSalesTotal();
		void setSalesTotal(double newTotal);
		void print();
};

#endif 



Source 1
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
#define _CRT_SECURE_NO_WARNINGS

#include "Seller.h"
#include <string>
#include <iostream>
#include <iomanip>

void Seller(){
	strcpy_s(Seller::name, "");
	Seller::total = 0;
}

void Seller(char nameArray[], double salesTotal){
	strcpy(nameArray, Seller::name);
	Seller::total = salesTotal;
} 

char* getName(){
	return Seller::name;
}

double getSalesTotal(){
	return Seller::total;
}

void setSalesTotal(double newTotal){
	Seller::total = newTotal;
}

void print(){
	std::cout << std::setw(30);
	std::cout << std::left << Seller::name;
	std::cout << std::setw(9);
	std::cout << std::right << std::fixed << std::setprecision(2) << Seller::total << std::endl;
}



Source 2
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 "Seller.h"

using std::cout;
using std::endl;

int main()
{
	// Test default constructor
	Seller seller1;

	// Test alternate constructor
	char s[] = "Jones, Martin";
	Seller seller2(s, 1234.56);

	// Test print() method and whether constructors
	// properly initialized objects
	cout << "Printing seller1\n\n";
	seller1.print();
	cout << endl << endl;

	cout << "Printing seller2\n\n";
	seller2.print();
	cout << endl << endl;

	// Test accessor methods
	cout << seller2.getName() << endl;
	cout << seller2.getSalesTotal() << endl;

	seller2.setSalesTotal(6543.21);
	cout << seller2.getSalesTotal() << endl;

	return 0;
}



I have a feeling that I'm making a really simple error somewhere, but I haven't been able to find it in a few hours. I would really appreciate a fresh set of eyes on this.

Thank you for your time
Hmm. Are they in the same directory? Did you make a typing mistake in the file name?
You could copy and paste the error message here?
What are the errors? We're not mind readers.
Errors are


1
2
3
4
5
6
7
8
9
10
Error	1	error LNK2019: unresolved external symbol "public: __thiscall Seller::Seller(void)" (??0Seller@@QAE@XZ) referenced in function _main	C:\Users\Kurt\Documents\Visual Studio 2013\Projects\SellerProject\SellerProject\assignment2.obj	SellerProject
Error	2	error LNK2019: unresolved external symbol "public: __thiscall Seller::Seller(char * const,double)" (??0Seller@@QAE@QADN@Z) referenced in function _main	C:\Users\Kurt\Documents\Visual Studio 2013\Projects\SellerProject\SellerProject\assignment2.obj	SellerProject
Error	3	error LNK2019: unresolved external symbol "public: char * __thiscall Seller::getName(void)" (?getName@Seller@@QAEPADXZ) referenced in function _main	C:\Users\Kurt\Documents\Visual Studio 2013\Projects\SellerProject\SellerProject\assignment2.obj	SellerProject
Error	4	error LNK2019: unresolved external symbol "public: double __thiscall Seller::getSalesTotal(void)" (?getSalesTotal@Seller@@QAENXZ) referenced in function _main	C:\Users\Kurt\Documents\Visual Studio 2013\Projects\SellerProject\SellerProject\assignment2.obj	SellerProject
Error	5	error LNK2019: unresolved external symbol "public: void __thiscall Seller::setSalesTotal(double)" (?setSalesTotal@Seller@@QAEXN@Z) referenced in function _main	C:\Users\Kurt\Documents\Visual Studio 2013\Projects\SellerProject\SellerProject\assignment2.obj	SellerProject
Error	6	error LNK2019: unresolved external symbol "public: void __thiscall Seller::print(void)" (?print@Seller@@QAEXXZ) referenced in function _main	C:\Users\Kurt\Documents\Visual Studio 2013\Projects\SellerProject\SellerProject\assignment2.obj	SellerProject
Error	7	error LNK2001: unresolved external symbol "public: static char * Seller::name" (?name@Seller@@2PADA)	C:\Users\Kurt\Documents\Visual Studio 2013\Projects\SellerProject\SellerProject\Seller.obj	SellerProject
Error	8	error LNK2001: unresolved external symbol "public: static double Seller::total" (?total@Seller@@2NA)	C:\Users\Kurt\Documents\Visual Studio 2013\Projects\SellerProject\SellerProject\Seller.obj	SellerProject
Error	9	error LNK1120: 8 unresolved externals	C:\Users\Kurt\Documents\Visual Studio 2013\Projects\SellerProject\Debug\SellerProject.exe	SellerProject

closed account (E0p9LyTq)
You were so close:

Seller.h:
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
#ifndef SELLER_H
#define SELLER_H

//*****************************************************************
// FILE:      Seller.h
// AUTHOR:    your name
// LOGON ID:  your z-ID
// DUE DATE:  due date of assignment
// 
// PURPOSE:   Contains the declaration for the Seller class.
//*****************************************************************

class Seller
{
   // Data members and method prototypes for the Seller class go here
public:
   std::string name;
   double total;

   Seller();
   Seller(std::string sellerName, double salesTotal);
   std::string getName();
   double getSalesTotal();
   void setSalesTotal(double newTotal);
   void print();
};

#endif  


Seller.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
35
36
37
38
39
40
41
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <iomanip>
#include "Seller.h"

Seller::Seller()
{
   name = "Generic Seller";
   total = 0;
}

Seller::Seller(std::string sellerName, double salesTotal)
{
   name = sellerName;
   total = salesTotal;
}

std::string Seller::getName()
{
   return name;
}

double Seller::getSalesTotal()
{
   return total;
}

void Seller::setSalesTotal(double newTotal)
{
   total = newTotal;
}

void Seller::print()
{
   std::cout << std::setw(30);
   std::cout << std::left << name;
   std::cout << std::setw(9);
   std::cout << std::right << std::fixed << std::setprecision(2) << total << std::endl;
}


main_source.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
35
#include <iostream>
#include <string>
#include "Seller.h"

using std::cout;
using std::endl;

int main()
{
   // Test default constructor
   Seller seller1;

   // Text alternate constructor
   std::string s = "Jones, Martin";
   Seller seller2(s, 1234.56);

   // Test print() method and whether constructors
   // properly initialized objects
   cout << "Printing seller1\n";
   seller1.print();
   cout << endl;

   cout << "Printing seller2\n";
   seller2.print();
   cout << endl << endl;

   // Test accessor methods
   cout << seller2.getName() << endl;
   cout << seller2.getSalesTotal() << endl;

   seller2.setSalesTotal(6543.21);
   cout << seller2.getSalesTotal() << endl;

   return 0;
}


I used a C++ string because using a char array crashed the program after initializing the two objects. And I was too lazy to try to fix the problem to work with a char array.

Here's the output of the revised program:
Printing seller1
Generic Seller                     0.00

Printing seller2
Jones, Martin                   1234.56


Jones, Martin
1234.56
6543.21
Last edited on
Thanks, FurryGuy. Never would've found that without help haha.
closed account (E0p9LyTq)
You are welcome.

BTW, I figured out why the char array crashed the program. It was your 2nd constructor, when you tried to copy the passed char array to the member char array.

You transposed the strcpy() parameters.

I still prefer C++ strings in C++ code, easier to deal with.
Last edited on
Topic archived. No new replies allowed.