...

View Full Version : Total newb C++ problem..



TurkeyMaster77
11-02-2008, 08:47 PM
I keep getting errors when I begin to include strings in my custom classes!! Actual program is more complex, but here's where I'm hitting problem.
It's throwing all kind of exceptions concerning 'string' identifiers, missing type specifiers and missing ';'s. Thanks

Driver.cpp:

#include <iostream>
#include <string>

#include "Custom.h"

using namespace std;

int main () {
Custom testClass ("test");
return 1;
}

Custom.h:

class Custom {
public:
Custom (string p_title);
private:
string title;
}

Custom.cpp:

#include <iostream>
#include <string>

#include "Custom.h"

using namespace std;

Custom::Custom (string p_title) {
title = p_title;
}

oracleguy
11-02-2008, 09:17 PM
You need to put the include for the string header file and the using statement in the custom.h file before the class declaration. Header files should stand on their own and pull in any needed dependencies themselves.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum