I am not very familiar with C ++ and how instance objects work, so this is probably a very simple task. When I compile with g ++, I get the error message "undefined reference to" Foo :: Foo (std :: string) ". I want to create an instance of the Foo class that has a string parameter in its constructor. Here is the code:
foo.h
#include <string>
using namespace std;
class Foo
{
public:
Foo(string s);
private:
string id;
};
foo.cpp
#include <string>
#include "Foo.h"
using namespace std;
Foo::Foo(string s)
{
id = s;
}
main.cpp
#include <string>
#include "Foo.h"
using namespace std;
int main()
{
Foo foo("bar");
return 0;
}
source
share