Link to home
Start Free TrialLog in
Avatar of grantws
grantws

asked on

LNK2019 error working with header file creation.

Hello,

 Please forgive my ignorance on this one, but I have been fighting with this for too long now.
 I have a program that I am writing that requires several classes to be designed and utilized. In the course of designing the
header files for the classes, I must break the class declarations (within the header files) apart from the class coding.
ie....

/* this is all in HEADERNAME.h */
#ifndef _HEADERNAME_H_
#define  _HEADERNAME_H_

someclass
{
 ......
 ......
}

#endif

/* this is all in HEADERNAME.cpp */
#include ".\headername.h"

someclass::someclass( void )
{........}

someclass::~someclass( void )
{........}

etc......


 My problem is that my compiler (Visual Studio.net 2003) runs fine if the entire class content is in the .h file, but gives me an error LNK2019 when I attempt to break the file into the .h file and the .cpp file.

 Any help would be awesome. Thank you in Advance!
 William Sean Grant
Avatar of lakshman_ce
lakshman_ce

Please post the full error message.
Add cpp file to the project.
The information is not sufficient.
Avatar of grantws

ASKER

I have placed: #include "OrderedList.h"
in the main program .cpp file. Below is just one of the many LNK2019 errors I get, though they are all the same error and just related to the other functions of the class Node and class OrderedList. As far as I can tell, my .h and .cpp files are included in my project (checking the solution explorer on the right side of the screen). As I mentioned above, if I force all of the function definitions in the .h file and compile, everything works as advertised.

Polynomials error LNK2019: unresolved external symbol "public: __thiscall OrderedList<char>::OrderedList<char>(void)" (??0?$OrderedList@D@@QAE@XZ) referenced in function _main


This is my Header file:

#pragma once
#include "profile.h"

/*
Predefined OrderedList class to use with Node class. The OrderedList class will
be fully defined after the Node class.
*/
template <class T>
class OrderedList;


/*
Node Class is the primary data storage structure to be used with the OrderedList class.
Includes a friend declaration for the OrderedList class which allows the OrderedList class
to utilize the Node structure as if it were Node were a OrderedList class member.
*/
template <class T>
class Node
{
 friend class OrderedList<T>;
 private:
    T* data;                                                            // Template type data
      Node<T> *next;                                                      // Address of next Node in list
      Node<T> *prev;                                                      // Address of previous Node in list

      Node( void );                                                      // Default Node constructor declaration
      virtual ~Node( void );                                          // Default Node destructor declaration
      Node<T>* operator=( const Node<T>& nodeIn );      // Node operator overloaded "equals" type Node
      Node<T>* operator=( const T& nodeIn );                  // Node operator overloaded "equals" type data
      bool operator==( const Node<T>& nodeIn );            // Node operator overloaded "is equal to" type Node
      bool operator==( const T& nodeIn );                        // Node operator overloaded "is equal to" type data
      bool operator!=( const Node<T>& nodeIn );            // Node operator overloaded "is not equal to" type Node
      bool operator!=( const T& nodeIn );                        // Node operator overloaded "is not equal to" type data
      bool operator<( const Node<T>& nodeIn );            // Node operator overloaded "is less than" type Node
      bool operator<( const T& nodeIn );                        // Node operator overloaded "is less than" type data
      bool operator>( const Node<T>& nodeIn );            // Node operator overloaded "is greater than" type Node
      bool operator>( const T& nodeIn );                        // Node operator overloaded "is greater than" type data
      bool operator<=( const Node<T>& nodeIn );            // Node operator overloaded "is lt or equal to" type Node
      bool operator<=( const T& nodeIn );                        // Node operator overloaded "is lt or equal to" type data
      bool operator>=( const Node<T>& nodeIn );            // Node operator overloaded "is gt or equal to" type Node
      bool operator>=( const T& nodeIn );                        // Node operator overloaded "is gt or equal to" type data
};

/* OrderedList Class declaration. */
template <class T>
class OrderedList
{
 private:
    long unsigned int size;                                           // Size of the list ( the number of Nodes in list )
      long unsigned int cpos;                                           // Current position of the list
      Node<T> *theList;                                                 // Initial data container for the list
      Node<T> *currentNode;                                           // Current data container pointed to within the list

      bool advanceNode( void );                                     // Function to advance the current Node in the list by one
      bool reverseNode( void );                                     // Function to rewind the current Node in the list by one
      bool beginNode( const T& dataIn );                         // Function to initialize the list
      bool insertFirst( const T& dataIn );                   // Function to insert data into the first position in the list
      bool insertMid( const T& dataIn );                         // Function to insert data into the middle positions in the list
      bool insertLast( const T& dataIn );                         // Function to insert data into the last position in the list
      bool removeFirst( void );                                     // Function to remove data from the first position in the list
      bool removeMid( void );                                           // Function to remove data from the middle positions in the list
      bool removeLast( void );                                     // Function to remove data from the last position in the list

public:
      OrderedList( void );                                           // Default constructor for the OrderedList class
      virtual ~OrderedList( void );                               // Default destructor for the OrderedList class

      void printOut( void );                                           // Function to printout list contents for testing purposes only
      bool isEmpty( void );                                           // Function to indicate if the list is empty
      long unsigned int sizeOf( void );                         // Function to return size of the list
      bool clearList( void );                                           // Function to clear the list
      bool setFirst( void );                                           // Function to move to the front of the list
      bool setPosition( const unsigned long int& pos );// Function to set the position that the list is currently at
      bool setDataPosition( const T& dataIn );             // Function to find the poisition that contains the input data
      long unsigned int returnCurrentPosition( void ); // Function to return the current position within the list
      bool removeData( const long unsigned int& pos ); // Function to remove data from the list
      T retrieveData( const long unsigned int& pos );  // Function to retreive data from the list without removing it
      bool insertData( const T& dataIn );                         // Function to insert data into the list
};


This is a portion of my .cpp file:
#include ".\orderedlist.h"


/*
Class Node constructor to create Node class with no input arguments.
Creates template data variable, NULL pointer to next Node in list, and
NULL pointer to previous Node in list.
*/
template <class T>
Node<T>::Node( void )
{
    data = new T;
      next = NULL;
      prev = NULL;
}

/*
Class Node default constructor to delete Node class with no input arguments.
Deletes template data variable. Makes next pointer and previous pointer NULL
address locations.
*/
template <class T>
Node<T>::~Node( void )
{
      delete data;
      if( next ) delete next;
      if( prev ) delete prev;

      next = NULL;
      prev = NULL;
}

more code follows..............................

/*
Class OrderedList default constructor. Sets size of list to 0 and the current position to the first Node
in the list, which is also 0. The initial data storage position within the list is initialized as "theList."
"currentNode" is set to the address of theList as the only Node in the list.
*/
template <class T>
OrderedList<T>::OrderedList( void )
{
      size = 0;
      cpos = 0;
      theList = new Node<T>;
      currentNode = theList;
}

/*
Class OrderedList default destructor. This function sets the values of the class to the original default values,
while deleting the Nodes for data holding.
*/
template <class T>
OrderedList<T>::~OrderedList( void )
{
      size = 0;
      cpos = 0;
      delete theList;
      currentNode = NULL;
}



more code follows..............................



Again, thank you in advance.
William Sean Grant
ASKER CERTIFIED SOLUTION
Avatar of e_tadeu
e_tadeu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of grantws

ASKER

Thank you e_tadeu and rajeev_devin, both, for your help. I truly appreciate the assist.
William Sean Grant
Grant,

  I think I deserved the Accepted Answer, rajeev's answer was just adding a little to my answer (he should have got a Good Assist)
Avatar of grantws

ASKER

I appologize, I am new to this site and am mucking through.
Thank you both, again.

William Grant