BofADev
asked on
Getting a linker error I don't understand
Can someone tell me why I'm getting a error LNK2001: unresolved external symbol "private: static double Dog::dblLicenseFee"(?dblLi censeFee@D og@@0NA) with the below code.
#include <iostream>
#include <string>
using namespace std;
class Dog {
public:
Dog();
void SetNameBreedAge(string, string, int);
void DisplayNameBreedAge();
private:
string strName, strBreed;
int intAge;
static double dblLicenseFee;
};
Dog::Dog(){
strName = "";
strBreed = "";
intAge = 0;
dblLicenseFee = 12.25;
}
void Dog::DisplayNameBreedAge() {
cout << strName << strBreed << intAge << dblLicenseFee << endl;
}
void Dog::SetNameBreedAge(strin g strName, string strBreed, int intAge){
}
int main(){
Dog myDog;
myDog.SetNameBreedAge ("Fluffy", "Lab", 1);
myDog.DisplayNameBreedAge( );
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class Dog {
public:
Dog();
void SetNameBreedAge(string, string, int);
void DisplayNameBreedAge();
private:
string strName, strBreed;
int intAge;
static double dblLicenseFee;
};
Dog::Dog(){
strName = "";
strBreed = "";
intAge = 0;
dblLicenseFee = 12.25;
}
void Dog::DisplayNameBreedAge()
cout << strName << strBreed << intAge << dblLicenseFee << endl;
}
void Dog::SetNameBreedAge(strin
}
int main(){
Dog myDog;
myDog.SetNameBreedAge ("Fluffy", "Lab", 1);
myDog.DisplayNameBreedAge(
return 0;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER
Ok I moved it after the class and it works. Interesting that it matters where you put things :)
> 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.
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.
ASKER