Thursday, 24 November 2011

Same Error for All Compiling (String)

Same Error for All Compiling (String)

Hi All,

I'm getting this identicaly error (obviously with different file names and classes shown) for every file I try to compile right now that has #include <string>

This particular one is an example that is actually just trying to compile an example from the book I'm using:

Code:

fig03_17.cpp:(.text+0x45): undefined reference to `GradeBook::GradeBook(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
Thought it was me so I spent hours yesterday trying to clean basic code up and ultimately failed, finally decided to just try to compile the cpp that is included in chapter 3 of my book that I am using to learn C++. Any ideas??


Here's an idea of my code, really really basic:

Account.h

Code:

//Chapter 3, Accounts Exercise: Accounts.h
//Presents the public interface of the class
//Member function definitions appear in Accounts.cpp


#include <string>
using namespace std;

class Account
{
public:
        Account ( string );
        void setAccountName ( string );
        string getCourseName ();
private:
        string accountName;
};


Account.cpp

Code:

//Chapter 3, Accounts Exercise: Accounts.cpp
//Implementations of the Accounts member-function definitions.
//Some functions perform validations


#include <iostream>
#include "Account.h"
using namespace std;

Account::Account (string name)
{
        setAccountName (name);
}

void Account::setAccountName (string name)
{
        accountName = name;
}

string Account::getAccountName
{
        return accountName;
}


Main.cpp

Code:

//Chapter 3, Accounts Exercise: Main.cpp
//Create and manipulate Account object

#include <iostream>
#include "Account.h"
using namespace std;

int main()
{
        Account myAccount("Test");
}

No comments:

Post a Comment