Thread: static declaration creates linker error

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    40

    static declaration creates linker error

    When I run the code below with the private LinkedList declared without the static qualifier, it compiles and runs exactly as I expect. As soon as I add the static declaration, I get linker errors and it can't find the LinkedList. Any thoughts?

    Code:
    #ifndef CS240_URL_SET_H
    #define CS240_URL_SET_H
    
    //Dustin Nicholes
    //October 21, 2008
    //CS 240
    //URLSet.h
    
    #include "URL.h"
    #include "LinkedList.h"
    #include "StringUtil.h"
    
    class URLSet
    {
    	private:
    		static LinkedList<URL> urlSet;
    	public:
    		URLSet()
    		{}
    	
    		bool addURL(URL & url)
    		{
    			if(!Contains(url))
    			{
    				urlSet.Insert(new URL(url), NULL);
    				return true;
    			}
    			return false;
    		}
    		
    		bool Contains(URL & url)
    		{
    			LLNode<URL> *LLCurrent;
    			LLCurrent=urlSet.GetFirst();
    			string scheme = StringUtil::ToLowerCopy(url.getScheme());
    			string netLoc = StringUtil::ToLowerCopy(url.getNetLocation());
    			string path = url.getPath();
    			
    			while(LLCurrent)
    			{
    				string otherString((LLCurrent->value)->toString());
    				URL other(otherString);
    				string otherScheme = StringUtil::ToLowerCopy(other.getScheme());
    				string otherNetLoc = StringUtil::ToLowerCopy(other.getNetLocation());
    				string otherPath = other.getPath();
    				
    				string thisString(scheme+netLoc+path);
    				string thatString(otherScheme+otherNetLoc+otherPath);
    				
    				if(thisString.compare(thatString)==0)
    					return true;
    				LLCurrent = LLCurrent->next;
    			}
    			return false;
    		}
    		
    		static bool Test(ostream & os)
    		{
    			os<<"Starting URL Set Test: ";
    			bool success = true;
    			
    			string urlString("http://students.cs.byu.edu/~cs240ta/util_docs/");
    			URL url1(urlString);
    			urlString="http://students.cs.byu.edu/~cs240ta/fall2008/";
    			URL url2(urlString);
    			urlString="http://students.cs.byu.edu/~cs240ta/fall2008/TA/";
    			URL url3(urlString);
    			urlString="HtTp://students.cs.byu.edu/~cs240ta/fall2008/TA/";
    			URL url4(urlString);
    			urlString="http://students.cs.byu.edu/bogus/";
    			URL url5(urlString);
    			
    			URLSet testSet;
    			TEST(testSet.addURL(url1));
    			TEST(testSet.addURL(url2));
    			TEST(testSet.addURL(url3));
    			TEST(!testSet.addURL(url4));
    			
    			TEST(testSet.Contains(url1));
    			TEST(testSet.Contains(url2));
    			TEST(testSet.Contains(url3));
    			TEST(!testSet.Contains(url5));
    						
    			if(success)
    				os<<"Passed\r\n";
    			else
    				os<<"Failed!!\r\b";
    			
    			return success;
    		}
    };
    
    #endif

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Why do you want the list to be static (so that there is only ever one list for all instances of your class).

    The solution is to have:

    Code:
    URLSet::LinkedList<URL> urlSet;
    somewhere in your source code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM