//CD.cpp
#include "iostream"
#include "CD.h"
usingnamespace std;
//method: set min and max d's
void CD::setd(double mind, double maxd) {
_mind = mind;
_maxd = maxd;
}
CD::~CD() {
}
If I set the method to be static, then I get the following error: "cannot declare member function 'static void CD::setd(double, double)' to have static linkage".
Thank you in advance for your help!
A class represents a "thing", but the class itself is not actually a thing. You need to create objects of that class. Each object is its own thing.
For example... string is a class. This means that you can have multiple "objects" of type string. Each has its own string data.
1 2
string foo = "hi";
string bar = "there";
Here, foo and bar are both strings. Now you can call member functions (such as the length function) by using the object name and the dot operator:
size_t len = foo.length(); // get the length of the foo string
But without an object, a call to length makes no sense:
1 2 3 4
size_t len = string::length(); // ?? what string are we getting the length of?
// is it foo? is it bar? is it something else?
// doesn't make any sense!
// so the compiler will give this line an error.
This is basically what you're doing. You're trying to call setd, but you're not telling the compiler which CD object you want to set. So it spits that error at you.