I have the following code but every time I go to compile it i get the same 3 errors and do not know why I am getting them. I have tried googling why but can't really understand any explanations that I am given and therefore cannot fix the errors. Any help understand why I am receiving these errors and what I need to do to fix them will be greatly appreciated. The errors are as followed:

1>orderset.obj : error LNK2005: "struct List * Head" (?Head@@3PAUList@@A) already defined in main.obj
1>orderset.obj : error LNK2005: "struct List * Last" (?Last@@3PAUList@@A) already defined in main.obj
1>C:\Users\Mike\Desktop\Mike.Stuff\School\c++\c++ spring cs2\pro2\Debug\pro2.exe : fatal error LNK1169: one or more multiply defined symbols found

Code Below:

orderset.h

#include <iostream>   

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

const int SUCCESS = 0;

//===================================================================

struct List{   

	int data;   

	List *next;   

};   // end of struct

List *Head, *Last;

//===================================================================

class OrderSet{   

public:   

	OrderSet();   

	OrderSet(OrderSet &data);   

	~OrderSet();   

	// Member functions

	OrderSet union1();   

	OrderSet intersection();   

	OrderSet find();   

	OrderSet add();   

	OrderSet test();   

	OrderSet getADTA();   

	OrderSet getADTB();   

	OrderSet showADTA();   

	OrderSet showADTB();   

	void mainMenu();   

private:   

	List a;   

	List b;   

};   // end of class

********************************
main.cpp

#include "orderset.h"   

int main()   
{
	OrderSet o;  

	o.mainMenu();   

	return SUCCESS;

}   // end of main

******************************
orderset.cpp

#include "orderset.h"   

OrderSet::OrderSet()   
{
}   // end of constructor

//===============================

OrderSet::~OrderSet()   // header the builds the de-constructor for the class
{
}   // end of de-contructor

//=================================

void OrderSet::mainMenu(){

	int option = 0;

	OrderSet m;

	cout << "Please select an option to execute by entering the number." << endl << endl;

	cout << "[1] Union of sets A and B\n";
	cout << "[2] Intersections of sets A and B\n";
	cout << "[3] Find an element X in set A\n";
	cout << "[4] Add an element X to A\n";
	cout << "[5] Determine whether A < B\n";
	cout << "[6] Terminate\n\n";

	cout << "Enter your option now:  ";

	cin >> option;

	if( option < 1 || option > 6 ){

		cout << "\nError, option selected is not valid, please try again!." << endl << endl;

		return;

	}   // end of if

	if( option == 1 ){

		cout << "\nYou selected option 1; to union the sets of list A and B." << endl << endl;

		m.mainMenu();
	
	}   // end of if

	if( option == 2 ){

		cout << "\nYou have selected option 2; to intersect the sets of A and B." << endl << endl;

		m.mainMenu();
		
	}   // end of if

	if( option == 3 ){

		cout << "\nYou have selected option 3; to find an element X in list A." << endl << endl;

		m.mainMenu();
		
	}   // end of if

	if( option == 4 ){

		cout << "\nYou have selected option 4; to add a new element X to list A." << endl << endl;

		m.mainMenu();
		
	}   // end of if

	if( option == 5 ){

		cout << "\nYou have selected option 5; to see if list A < list B." << endl << endl;

		m.mainMenu();
		
	}   // end of if

	if( option == 6 ){

		cout << "\nYou have selected option 6; to terminate the progam.\n";

		cout << "Thank you for for using our program, have a nice day =]!" << endl << endl;

		return;

	}   // end of if

}   // end of function mainMenu

//==========================

Never mind with fixing the error I just had to move the line

List *Head, *Last;

from under the struct to inside the private part of the class. But I still do not understand why I had to do this so any help explaining that to me, thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.