Question

Hello, this is my code and it have redefinition error, please help me to fix it...

Hello, this is my code and it have redefinition error, please help me to fix it

//doublenode.hpp

#ifndef DOUBLENODE_HPP

#define DOUBLENODE_HPP

template<class ItemType>

class DoubleNode

{

private:

ItemType item;

DoubleNode<ItemType>* next;

DoubleNode<ItemType>* prev;

public:

DoubleNode();

DoubleNode(const ItemType& anItem);

DoubleNode(const ItemType& anItem,DoubleNode<ItemType>* nextNodePtr, DoubleNode<ItemType>* previousNodePtr);

void setItem(const ItemType& anItem);

ItemType getItem() const;

void setNext(DoubleNode<ItemType>* nextNodePtr);

DoubleNode<ItemType>* getNext() const;

void setprevious(DoubleNode<ItemType>* previousNodePtr);

DoubleNode<ItemType>* getPrevious() const;

};

#include "DoubleNode.cpp"

#endif


//doblenode.cpp

//#ifndef DOUBLE_NODE_CPP

//#define DOUBLE_NODE_CPP

#include "DoubleNode.hpp"

template <class ItemType>

DoubleNode<ItemType>::DoubleNode():next(nullptr),prev(nullptr)

{

}

template <class ItemType>

DoubleNode<ItemType>::DoubleNode(const ItemType& anItem):item(anItem),next(nullptr),prev(nullptr)

{

}

template <class ItemType>

DoubleNode<ItemType>::DoubleNode(const ItemType& anItem,DoubleNode<ItemType>* nextNodePtr, DoubleNode<ItemType>* previousNodePtr):item(anItem),next(nextNodePtr),prev(previousNodePtr)

{

}

template <class ItemType>

void DoubleNode<ItemType>::setItem(const ItemType& anItem)

{

item=anItem;

}

template <class ItemType>

ItemType DoubleNode<ItemType>::getItem() const

{

return item;

}

template <class ItemType>

void DoubleNode<ItemType>::setNext(DoubleNode<ItemType>* nextNodePtr)

{

next=nextNodePtr;

}

template <class ItemType>

DoubleNode<ItemType>* DoubleNode<ItemType>:: getNext() const

{

return next;

}

template <class ItemType>

void DoubleNode<ItemType>::setprevious(DoubleNode<ItemType>* previousNodePtr)

{

prev=previousNodePtr;

}

template <class ItemType>

DoubleNode<ItemType>* DoubleNode<ItemType>:: getPrevious() const

{

return prev;

}


//#endif

0 0
Add a comment Improve this question Transcribed image text
Answer #1

remove '#include "DoubleNode.cpp" ' from doublenode.hpp .

//doublenode.hpp

#ifndef DOUBLENODE_HPP

#define DOUBLENODE_HPP

template<class ItemType>

class DoubleNode

{

private:

ItemType item;

DoubleNode<ItemType>* next;

DoubleNode<ItemType>* prev;

public:

DoubleNode();

DoubleNode(const ItemType& anItem);

DoubleNode(const ItemType& anItem,DoubleNode<ItemType>* nextNodePtr, DoubleNode<ItemType>* previousNodePtr);

void setItem(const ItemType& anItem);

ItemType getItem() const;

void setNext(DoubleNode<ItemType>* nextNodePtr);

DoubleNode<ItemType>* getNext() const;

void setprevious(DoubleNode<ItemType>* previousNodePtr);

DoubleNode<ItemType>* getPrevious() const;

};

// #include "DoubleNode.cpp"

#endif

//doblenode.cpp

//#ifndef DOUBLE_NODE_CPP

//#define DOUBLE_NODE_CPP

#include "DoubleNode.hpp"

template <class ItemType>

DoubleNode<ItemType>::DoubleNode():next(nullptr),prev(nullptr)

{

}

template <class ItemType>

DoubleNode<ItemType>::DoubleNode(const ItemType& anItem):item(anItem),next(nullptr),prev(nullptr)

{

}

template <class ItemType>

DoubleNode<ItemType>::DoubleNode(const ItemType& anItem,DoubleNode<ItemType>* nextNodePtr, DoubleNode<ItemType>* previousNodePtr):item(anItem),next(nextNodePtr),prev(previousNodePtr)

{

}

template <class ItemType>

void DoubleNode<ItemType>::setItem(const ItemType& anItem)

{

item=anItem;

}

template <class ItemType>

ItemType DoubleNode<ItemType>::getItem() const

{

return item;

}

template <class ItemType>

void DoubleNode<ItemType>::setNext(DoubleNode<ItemType>* nextNodePtr)

{

next=nextNodePtr;

}

template <class ItemType>

DoubleNode<ItemType>* DoubleNode<ItemType>:: getNext() const

{

return next;

}

template <class ItemType>

void DoubleNode<ItemType>::setprevious(DoubleNode<ItemType>* previousNodePtr)

{

prev=previousNodePtr;

}

template <class ItemType>

DoubleNode<ItemType>* DoubleNode<ItemType>:: getPrevious() const

{

return prev;

}

//#endif

please upvote if it helped.

Add a comment
Know the answer?
Add Answer to:
Hello, this is my code and it have redefinition error, please help me to fix it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Error. I'm having trouble with a pointer. I keep getting the error "Thread 1: EXC_BAD_ACCESS...

    C++ Error. I'm having trouble with a pointer. I keep getting the error "Thread 1: EXC_BAD_ACCESS (code=1, address=0x18)" The objective of the assignment is to revise the public method add in class template LinkedBag so that the new node is inserted at the end of the linked chain instead of at the beginning. This is the code I have: linkedBag-driver.cpp BagInterface.hpp LinkedBag.hpp Node.hpp int main) LinkedBag<string> bag; cout << "Testing array-based Set:" << endl; cout << "The initial bag is...

  • This is a c++ class utilizing class templates and linked lists. I need to implement the...

    This is a c++ class utilizing class templates and linked lists. I need to implement the following member function(s) to List.cpp. Node.hpp/cpp should be fine but if you feel like there needs to be a change for compilation or testing, feel free to do so but make sure to comment on why it was done. /** @pre assumes position is valid, if position is > item_count_ it returns an empty List, also assumes that operators <= and >= are defined...

  • Double linked list implementation of PutItem function. How to fix my code to get desired output b...

    Double linked list implementation of PutItem function. How to fix my code to get desired output below: Output: 2 5 8 #ifndef ITEMTYPE_H #define ITEMTYPE_H enum RelationType { LESS, GREATER, EQUAL}; class ItemType { public:     ItemType();     void setValue(int newValue);     int getValue() const;     RelationType ComparedTo(ItemType newItem); private:     int value; }; #endif // ITEMTYPE_H // ItemType.cpp #include "ItemType.h" ItemType::ItemType() {     value = 0; } void ItemType::setValue(int newValue) {     value = newValue; } int ItemType::getValue() const {     return value; } RelationType ItemType::ComparedTo(ItemType newItem)...

  • This is a c++ class utilizing class templates and linked lists and Nodes. I need to...

    This is a c++ class utilizing class templates and linked lists and Nodes. I need to implement the following member function(s) to LinkedBag.cpp. Node.hpp/cpp should be fine but if you feel like there needs to be a change for compilation or testing, feel free to do so but make sure to comment on why it was done. In this case, I need to join the original items with the user items(a_bag). So if the original has {1,2,3} and a_bag has...

  • Given the following code: #ifndef TREE_H #define TREE_H #include <iostream> #include "TreeNode.h" template< typename NODETYPE > class Tree { public: Tree() : rootPtr( nullptr ) {}...

    Given the following code: #ifndef TREE_H #define TREE_H #include <iostream> #include "TreeNode.h" template< typename NODETYPE > class Tree { public: Tree() : rootPtr( nullptr ) {} void insertNode( const NODETYPE &value ) { insertNodeHelper( &rootPtr, value ); } void preOrderTraversal() const { preOrderHelper( rootPtr ); } void inOrderTraversal() const { inOrderHelper( rootPtr ); } private: TreeNode< NODETYPE > *rootPtr; void insertNodeHelper( TreeNode< NODETYPE > **ptr, const NODETYPE &value ) { if ( *ptr == nullptr ) * ptr = new...

  • Trace the following program. What is the output after execution? typedef double T; class PlainBox{ private:...

    Trace the following program. What is the output after execution? typedef double T; class PlainBox{ private: T item; public: PlainBox();   PlainBox(const T& theItem); void setItem(const T& itemItem); T getItem() const; friend ostream & operator<<(ostream & out, const PlainBox & theBox);   bool operator<(const PlainBox & theBox); }; PlainBox::PlainBox(){} PlainBox::PlainBox( const ItemType & theItem){ item = theItem; } void PlainBox:: setItem(const T& theItem){ item = theItem; } T PlainBox:: getItem () const { return item; } //remaining implementation is not shown source.cpp...

  • The program I wrote has a few memory leaks. My assignment is to just fix the...

    The program I wrote has a few memory leaks. My assignment is to just fix the memory leaks. Here's the code: bool RemoveTail() { if (tail == nullptr) return false; Node *ptr = tail; if(tail->prev != nullptr) { tail = tail->prev; tail->next = nullptr; } else { tail = nullptr; head = nullptr; } delete ptr; ptr = nullptr; length--; return true; } bool RemoveAt(const unsigned int index) { if(index >= length || index < 0) return false; unsigned int...

  • // Node.h #ifndef NODE_H #define NODE_H class Node { private: int m_entry; Node *m_next; public: Node();...

    // Node.h #ifndef NODE_H #define NODE_H class Node { private: int m_entry; Node *m_next; public: Node(); Node(int entry); int getEntry() const; void setEntry(int entry); Node *getNext(); void setNext(Node *next); }; #endif // Node.cpp #include "Node.h" Node::Node() { m_entry = 0; m_next = nullptr; } Node::Node(int entry) { m_entry = entry; } int Node::getEntry() const { return m_entry; } void Node::setEntry(int entry) { m_entry = entry; } Node *Node::getNext() { return m_next; } void Node::setNext(Node *next) { m_next = next; }...

  • Why is the answer 10 and 0 (respectively - two different answers, one is 10 and...

    Why is the answer 10 and 0 (respectively - two different answers, one is 10 and the second one is 0)? I don't know how to trace this. Please don't be too complex in your explanation. Consider the following class public class Node {     private int item;     private Node next;         public Node() {         this(0);     }     public Node(int item) {         this(item, null);     }     public Node(int item, Node next) {...

  • I need help with understanding dummy nodes in doubly-linked lists. Here is the code that I...

    I need help with understanding dummy nodes in doubly-linked lists. Here is the code that I have right now. ************city.h**************** #ifndef city_h #define city_h #include <string> using namespace std; class City{ public: City () { name = "N/A"; population = 0; } City (string nm, unsigned int pop){ name = nm; population = pop; } void setName (string name) { this -> name = name; } void setPopulation (unsigned int population){ this -> population = population; } string getName() const...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT