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:


#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{   



	OrderSet(OrderSet &data);   


	// Member functions

	OrderSet union1();   

	OrderSet intersection();   

	OrderSet find();   

	OrderSet add();   

	OrderSet test();   

	OrderSet getADTA();   

	OrderSet getADTB();   

	OrderSet showADTA();   

	OrderSet showADTB();   

	void mainMenu();   


	List a;   

	List b;   

};   // end of class


#include "orderset.h"   

int main()   
	OrderSet o;  


	return SUCCESS;

}   // end of main


#include "orderset.h"   

}   // 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;


	}   // end of if

	if( option == 1 ){

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

	}   // end of if

	if( option == 2 ){

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

	}   // end of if

	if( option == 3 ){

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

	}   // end of if

	if( option == 4 ){

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

	}   // end of if

	if( option == 5 ){

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

	}   // 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;


	}   // end of if

}   // end of function mainMenu

8 Years
Discussion Span
Last Post by buddha527

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.