364,034 Members | 4819 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

[Linker error] undefined reference to `WinMain@16'...

B_Love
P: 1
Hey! When trying to compile the code for a ordered vector class I get the following error:
[Linker error] undefined reference to `WinMain@16'

Anyone have any idea what I might be doing wrong? I've been through this code multiple times and have no idea what would cause an error like this, I've never seen one like it before. Any help would be greatly appreciated.

The class is supposed to be able to create a sorted list of vectors of type Object. If an object is added to the list it places it in the proper order (ie you want to put in a 5 in the list 2 3 4 6, the 5 would be inserted between the 4 and 6)

Code is as follows:

Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2. #include <iostream>
  3. #ifndef _ORDEREDVECTOR_H
  4. #define _ORDEREDVECTOR_H
  5.  
  6. template <class Object>
  7. class orderedVector
  8. {
  9.     public:
  10.         orderedVector(int n);
  11.         orderedVector( );
  12.         orderedVector(const orderedVector & v);
  13.         virtual ~orderedVector( );
  14.         void dissolve ( );
  15.         void add (const Object x);
  16.         void remove (const Object x);
  17.         void removeAt (int i);
  18.         Object & operator [](int i);
  19.         int length( ) const;
  20.         bool isEmpty( ) const;
  21.         bool contains(const Object x);
  22.     private:
  23.         Object * buffer;
  24.         int size, capacity;
  25.         void reserve(int newCapacity);
  26.         void resize(int newCap) {reserve(newCap);}
  27.     };
  28.  
  29.     template <class Object>
  30.     orderedVector<Object>::orderedVector( ) :size(0),capacity(0),buffer(0){}
  31.  
  32.     template <class Object>
  33.     orderedVector<Object>::orderedVector(int n): size(0), capacity(n), buffer(0) 
  34.     {
  35.         if (n < 0)
  36.         {
  37.             cerr << "Error: You can't create a vector with a negative capacity!\n";
  38.             exit(1);
  39.         }
  40.     }
  41.  
  42.     template <class Object>
  43.     orderedVector<Object>::orderedVector(const orderedVector & v) 
  44.     {
  45.         if (this == &v) 
  46.         {
  47.             cerr << "Error: You can't copy a vector onto itself!\n";
  48.             exit(1);
  49.         }
  50.         buffer = 0;
  51.         buffer = new Object[v.capacity];
  52.         size = v.length( );
  53.         capacity = v.capacity;
  54.  
  55.         for (int i = 0; i < v.length( ); i++) 
  56.         {
  57.             buffer[i] = v.buffer[i];
  58.         }
  59.     }
  60.  
  61.     template <class Object>
  62.     orderedVector<Object>::~orderedVector( ) 
  63.     {
  64.         delete [ ] buffer;
  65.     }
  66.  
  67.     template <class Object>
  68.     void orderedVector<Object>::add(const Object x) 
  69.     {
  70.         if (size == capacity)
  71.                 resize(capacity + 5);
  72.  
  73.         if (size == 0)
  74.                 buffer[0] = x;
  75.         else 
  76.         {
  77.             for (int i = 0; i < size; i++) 
  78.             {
  79.                 if (x <= buffer[i])
  80.                 {
  81.                     int j = size;
  82.                     while (j > i) 
  83.                     {
  84.                         buffer[j] = buffer[j-1];
  85.                         j--;
  86.                     }
  87.                     buffer[i] = x;
  88.                 }
  89.             }
  90.         }
  91.         size++;
  92.     }
  93.  
  94.     template <class Object>
  95.     void orderedVector<Object>::remove(const Object x) 
  96.     {
  97.         bool temp;
  98.         for (i = 0; i < size; i++) 
  99.         {
  100.             if (buffer[i] == x)
  101.                 temp = true;
  102.             else
  103.                 temp = false;
  104.         }
  105.  
  106.         if (temp == false) 
  107.         {
  108.             cerr << "Error: Object doesn't exist!\n";
  109.             exit(1);
  110.         }
  111.  
  112.         else 
  113.         {
  114.             for (int i = 0; i < size; i++)
  115.             {
  116.                 int j = i;
  117.                 while (j < size - 1) 
  118.                 {
  119.                     buffer[j] = buffer[j+1];
  120.                     j++;
  121.                 }
  122.             }
  123.             size--;    
  124.         }
  125.     }
  126.  
  127.     template <class Object>
  128.     void orderedVector<Object>::removeAt(const int i) 
  129.     {
  130.         if (i < 0 || i >= size) 
  131.         {
  132.              cerr << "Error: Index out of range!\n";
  133.              exit(1);
  134.         }
  135.  
  136.         int j = i;
  137.         while (j < size - 1)
  138.         {
  139.                buffer[j] = buffer[j+1];
  140.             j++;
  141.         }
  142.         size--;
  143.    }
  144.  
  145.    template <class Object>
  146.    Object & orderedVector<Object>::operator [] (int i)
  147.    {
  148.         if (i < 0 || i >= size) 
  149.         {
  150.              cerr << "Error: Index out of range!\n";
  151.              exit(1);
  152.         }
  153.         return buffer[i];
  154.    }
  155.  
  156.    template <class Object>
  157.    int orderedVector<Object>::length( ) const 
  158.    {
  159.        return size;
  160.    }
  161.  
  162.    template <class Object>
  163.    bool orderedVector<Object>::isEmpty( ) const 
  164.    {
  165.        return size == 0;
  166.    }
  167.  
  168.    template <class Object>
  169.    bool orderedVector<Object>::contains(const Object x) 
  170.    {
  171.         bool temp;
  172.         for (i = 0; i < size; i++) 
  173.         {
  174.             if (buffer[i] == x)
  175.                 temp = true;
  176.             else
  177.                 temp = false;
  178.  
  179.         }
  180.         return temp;
  181.     }
  182.  
  183.     template <class Object>
  184.     void orderedVector<Object>::reserve(int newCap)
  185.     {
  186.         if (buffer == 0)
  187.         {
  188.             size = 0;
  189.             capacity = 0;
  190.         }
  191.  
  192.         if (newCap <= capacity)
  193.                 return;
  194.  
  195.         Object * newBuffer = new Object[newCap];
  196.  
  197.         for (int i = 0; i < size; i++)
  198.                 newBuffer[i]=buffer[i];
  199.  
  200.         capacity = newCap;
  201.         delete [ ] buffer;
  202.         buffer = newBuffer;    
  203.     }
  204. #endif
Sep 26 '05 #1
Share this Question
Share on Google+
2 Replies


SomethingRandom
P: 1
Howzit going man,

I just saw your post...
I'm very sure you've already figured it out, but if you haven't its probably just that you have specified a int main() funtion in your project.

:)

Cheers,
Nic
May 16 '06 #2

Banfa
Expert Mod 5K+
P: 6,499
SomethingRandom is definately on the right lines, however your main may be correct, you have tried to compile/link the project as a Windows Application without defining the WinMain function.

WinMain replaces main as the entry point for Windows Applications so either you were trying to right a Windows application and left out WinMain or you wern't trying to write a Windows application and (hopefully) have a main but have compile/link with flags that tell the compiler/linker that this is a Windows application and probably linked with some of the Windows system libraries.

P.S. The problem has nothing to do with the header file you have posted.
May 16 '06 #3

Post your reply

Help answer this question



Didn't find the answer to your C / C++ question?

You can also browse similar questions: C / C++ error winmain@16