I am testing using classes and here's my problem: I get a linker error with undefined reference to my method, "void AddText(std::string)". Here's my code:
FSTR.cpp:
#include <iostream>
#include <string>
#include "FSTR.H"
using namespace std;
int main()
{
FSTR FSTR_M;
FSTR_M.AddText("test");
cin.get();
}
1. This isnt the reason i don't think but you should't have the class code and the definiton in the same source file, unless the methods are actually embedded in the class definition.
Change your method definition to be the same as well.
The reason for the const reference is because 'const' signifies to the person using the function that the code inside the function doesn't change the string. The reference '&' means that you are not passing the string by value, which is slow, rather by name, as it where. By value is slow because a fresh string the same as the original is created, by reference is like using the original. For this the code in the method doesn't need to change, a reference is treated the same as by value.