Thread: compiling problems LNK2019 error

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    17

    compiling problems LNK2019 error

    I am working on a project and am trying to compile as I go and I'm getting a linking problem. The main most of header file functions were given to us.

    Header
    Code:
    #ifndef INTEGERSET_H
    #define INTEGERSET_H
    
    const int arraySize = 100;
    
    class IntegerSet 
    {
    public:
    	IntegerSet();  //Default constructor empty set
    
    	//IntegerSet( int values[], int size );  //Constructor with values
    	~IntegerSet(); 
    
    	//IntegerSet& unionSet( IntegerSet& otherSet );
    	//IntegerSet& intersectSet( IntegerSet& otherSet );
    
    	//void clear();
    
    	//bool isEmptySet();
    	bool insertElement( int elem, int count = 1 );
    	//bool removeElement( int elem, int count = 1 );
    
    	//bool setElementCount( int elem, int count );
    	//int getNumElements( int elem );
    
    	//bool isEqualTo( IntegerSet& otherSet );
    
    	void printSet();
    
    private:
    	int array;
    
    };
    
    #endif
    IntegerSet.cpp
    Code:
    #include "IntegerSet.h"
    #include <iostream>
    #include <conio.h>
    #include <iomanip>
    
    using std::cout;
    using std::endl;
    using std::setw;
    
    
    static int array[ arraySize ];
    
    
    bool IntegerSet::insertElement( int elem, int counter )
    {
    	if( elem > 0 && elem <= arraySize )
    	{
    		return true;
    	}
    	else
    		return false;
    	
    }
    
    void IntegerSet::printSet()
    {
    	for( int idx = 0; idx < arraySize; ++idx )
    		cout << idx << ")" << setw( 3 ) << idx << endl;
    }
    main.cpp
    Code:
    #include "IntegerSet.h"
    #include <iostream>
    #include <conio.h>
    
    using std::cout;
    using std::endl;
    
    int main()
    {
    	int i;
    	IntegerSet a;
    
    	cout << "Empty Set" << endl;
    	a.printSet();
    	getch();
    
    	srand( 1234 );
    	for( i = 0; i < 50000; ++i )
    		a.insertElement( rand() % 101 );
    		a.printSet();
    	getch();
    
    /*	cout << "Random insert" << endl;
    	a.printSet();
    	getch();
    
    	int testArray[300];
    	for( i = 0; i < 300; ++i )
    		testArray[i] = rand() % 101;
    
    	IntegerSet b( testArray, 300 );
    
    	cout << "Fill from array" << endl;
    	b.printSet();
    	getch();
    
    	IntegerSet c = a;
    
    	cout << "Operator =" << endl;
    	c.printSet();
    	getch();
    
    	c.unionSet( b ).intersectSet( a );
    
    	cout << "Union b, intersect a" << endl;
    	c.printSet();
    	getch();
    
    	if( a.isEqualTo( c ) )
    		cout << "A and C are equivalent" << endl;
    	else
    		cout << "A and C are not equivalent" << endl;
    
    	if( b.isEmptySet() )
    		cout << "B is empty" << endl;
    	else
    		cout << "B is not empty" << endl;
    */
    
    	getch();
    	return 0;
    }
    Errors
    Code:
    MT fatal error LNK1120: 2 unresolved externals
    MT error LNK2019: unresolved external symbol "public: __thiscall IntegerSet::~IntegerSet(void)" (??1IntegerSet@@QAE@XZ) referenced in function _main
    MT error LNK2019: unresolved external symbol "public: __thiscall IntegerSet::IntegerSet(void)" (??0IntegerSet@@QAE@XZ) referenced in function _main
    I commented out most things b/c I'm trying to go one step at a time. I would appreciate any help.

  2. #2
    Registered User
    Join Date
    Feb 2005
    Posts
    17

    I figured that part out...

    I figured that part out but I have another question.

    In this printSet function how do I change the second idx so that it's the value of the array?

    Code:
    void IntegerSet::printSet()
    {
    	for( int idx = 0; idx < arraySize; ++idx )
    		cout << idx << ")" << setw( 3 ) << idx << endl;
    }

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    array[idx] will be the value at the index specified by idx.

    You have two variables called array in your code. One is a plain int (not an array) that is a member of your class. The other is a static array variable that is local to the IntegerSet.cpp file. I think maybe you want to only have one that is a member of the class and is an array.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM