I just copy-pasted my LinkedList into another source file LinkedList.cpp.
Inluded the file in my main.
Problem: When I compile, this is the error I get:
1>------ Build started: Project: LinkedList, Configuration: Debug Win32 ------ 1> FilterData.cpp 1>LinkedList.obj : error LNK2005: "public: void __thiscall LinkedList::Add(int)" (?Add@LinkedList@@QAEXH@Z) already defined in FilterData.obj 1>LinkedList.obj : error LNK2005: "public: void __thiscall LinkedList::PrintData(void)" (?PrintData@LinkedList@@QAEXXZ) already defined in FilterData.obj 1>C:\Users\Karan\documents\visual studio 2010\Projects\LinkedList\Debug\LinkedList.exe : fatal error LNK1169: one or more multiply defined symbols found ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
#include "LinkedList.cpp"
#include <iostream>
#include <cstring> // definitions for c string functions.
#include <fstream>
#include <sstream>
using namespace std;
int main(){
LinkedList ll;
int more;
ll.Add(78);
ll.Add(78);
ll.Add(200);
ll.Add(78);
ll.Add(300);
ll.Add(78);
ll.Add(200);
ll.Add(78);
ll.Add(300);
ll.Add(400);
ll.Add(78);
ll.Add(200);
ll.Add(78);
ll.Add(300);
ll.Add(78);
ll.Add(200);
ll.Add(78);
ll.Add(300);
ll.Add(400);
ll.Add(78);
ll.Add(200);
ll.Add(78);
ll.Add(300);
ll.Add(78);
ll.Add(200);
ll.Add(78);
ll.Add(300);
ll.Add(400);
ll.PrintData();
cout << "Do you want to exit" << endl;
cin >> more;
return 0;
}
Below is my LinkedList.cpp_______________________
#include <iostream>
#include <cstring> // definitions for c string functions.
#include <fstream>
#include <sstream>
using namespace std;
class Node {
public:
int number;
Node* next;
public:
void setData (int num){
number = num;
};
void setNext (Node* myNext){
next = myNext;
};
int getData(){
return number;
};
Node* myNext(){
return next;
};
};
class LinkedList{
Node *head;
public:
LinkedList(){
head = NULL;
};
public:
void Add (int data);
void Delete (int data);
void PrintData();
void check(int data);
};
void LinkedList::Add(int data){
Node *temp = head;
if(head == NULL){
Node* newNode = new Node();
(*newNode).setData(data);
(*newNode).setNext(NULL);
head = newNode;
}
else{
while((*temp).myNext() != NULL){
if((*temp).getData() == data){
(*temp).setData(data);
break;
}
else{
temp = temp->myNext();
}
}
if((*temp).myNext() == NULL && ((*temp).getData() != data)){
Node* newNode = new Node();
(*newNode).setData(data);
(*newNode).setNext(NULL);
(*temp).setNext(newNode);
}
}
};
void LinkedList::PrintData(){
Node *temp = head;
if(temp == NULL){
cout << "No Data" << endl;
return;
}
else{
if((*temp).myNext()==NULL){
cout << (*temp).getData() << endl;
}
else{
while(temp != NULL){
cout << (*temp).getData() << endl;
temp = (*temp).myNext();
}
}
}
};
This post has been edited by deprosun: 23 September 2012 - 09:09 AM

New Topic/Question
Reply



MultiQuote





|