Thread: Function Error

  1. #1
    diligentStudent()
    Join Date
    Apr 2002
    Posts
    79

    Function Error

    Hi. I am getting the following error message when I try to call the function I have outlined below. Any one know what the problem might be. Can I write this stand-alone function: Huff* findMinimum(vector<Huff*> v) in this context?
    Code:
    #include<iostream>
    #include<string>
    #include<vector>
    #include<fstream>
    #include<stack>
    using namespace std;
    
    struct Huff
    {
        Huff();
        int count;
        char ch;
        Huff* left;
        Huff* right;
        Huff* parent;
    };
    
    Huff* findMinimum(vector<Huff*>& v);
    
    int main(int argc, char* argv[])
    {
    	if(argc<2)
    	{
    	    cout<<"Not enough arguments were provided."<<endl;
    		return -1;
    	}
        ifstream myFile(argv[1], ios::in);
    	if(!myFile.is_open())
    	{
    	    cout<<"Unknown file specified."<<endl;
    		return -1;
    	}
    	char cz;
        int i;
        vector<Huff*> values;
        while(myFile.get(cz))
        {
            if(cz < 'a' || cz > 'z')
                continue;
            for(i=0; i<values.size(); i++)
            {
                if(values[i]->ch == cz)
                {
                    values[i]->count++;
                    break;
                }
            }
            if(values.size()==i)
            {
                Huff* h = new Huff;
                h->ch=cz;
                h->count=1;
                values.push_back(h);
            }
         }
         for(i=0; i<values.size(); i++)
             cout<<values[i]->ch<<values[i]->count<<endl;
         findMinimum(values);           /* Trouble with this line */
         return 0;
    }
    
    Huff::Huff() : ch(0), count(0) { }
    
    Huff* findMimimum(vector<Huff*>& v)
    {
         int index, minCo=v[0]->count;
         char minCh=v[0]->ch;
         index=0;
         for(int i=1; i<v.size(); i++)
         {
             if(v[i]->count < minCo)
             {
                 minCo=v[i]->count;
                 minCh=v[i]->ch;
                 index=i;
             }        
         }
    }
    Error Message:
    Code:
    [Warning] In function `main':
    [Linker error] undefined reference to `findMinimum(std::vector<Huff*, std::allocator<Huff*> >&)'
    Thanks in advance, Steve

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Check your spelling:
    Code:
    Huff* findMinimum(vector<Huff*>& v);
    Huff* findMimimum(vector<Huff*>& v)
    My best code is written with the delete key.

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Ah yes... Optinization can be quite fun.


    (Sorry, it's been a long day.)
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  4. #4
    diligentStudent()
    Join Date
    Apr 2002
    Posts
    79

    Thumbs up Thanx

    Thanx Prelude. As always, I really appreciate it.

    ~S.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM