Getting a linker error I don't understand

Posted on 2006-05-23
Last Modified: 2010-04-01
Can someone tell me why I'm getting a error LNK2001: unresolved external symbol "private: static double Dog::dblLicenseFee"(?dblLicenseFee@Dog@@0NA) with the below code.

#include <iostream>
#include <string>
using namespace std;

class Dog {
            void SetNameBreedAge(string, string, int);
            void DisplayNameBreedAge();
            string strName, strBreed;
            int intAge;
            static double dblLicenseFee;

      strName = "";
      strBreed = "";
      intAge = 0;
      dblLicenseFee = 12.25;

void Dog::DisplayNameBreedAge(){
      cout << strName << strBreed << intAge << dblLicenseFee << endl;

void Dog::SetNameBreedAge(string strName, string strBreed, int intAge){

int main(){
      Dog myDog;
      myDog.SetNameBreedAge ("Fluffy", "Lab", 1);
      return 0;
Question by:BofADev
    LVL 15

    Accepted Solution

    You declared Dog::dblLicenseFee but did not define it, so you said it exists somewhere, but did not allocate storage for it.  You can do that by adding a definition:

    double Dog::dblLicenseFee;

    If you separate the class declaration from the implementation, this definition should go in the implementation file, not the header file with the class declaration.

    Author Comment

    This makes sense now.  So the reason I have to decare dblLicenseFee and not the other members is because it is static?

    Author Comment

    Ok I put double Dog::dblLicenseFee; right between using namespace std; and class Dog and now it is telling me that Dog : is not a class or namespace.

    Author Comment

    Ok I moved it after the class and it works.  Interesting that it matters where you put things :)
    LVL 15

    Expert Comment

    > So the reason I have to decare dblLicenseFee and not the other members is because it is static?

    Yes.  The non-static members get storage allocated when you create an object of the class, but a static member is independent of any instance, so you have to allocate it separately.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now