[solved]29: error: ‘string’ does not name a type
Hi,
when try to compile my program I get the following message for this header file
Code:
#ifndef SENDSMS_H
#define SENDSMS_H
#include "ui_sendSMS.h"
#include <string>
class sendSMS : public QMainWindow, public Ui::MainWindow{
Q_OBJECT
public:
sendSMS (QMainWindow *parent = 0);
~sendSMS();
private slots:
void slotClose();
void calcChar();
void slotSend();
QString clean_string(QString);
QChar get_param(QString, int);
QString get_param_value(QString, int);
void process_line(QString);
void read_config_file();
private:
int maxChar;
QString param_filename;
string username;
string password;
string sourceno;
};
#endif
Ignore all the "Q" things, thats something Qt specific. int works fine, but not string. I have the string header included. I guess it is rather simple what is wrong....
Thanks,
J.
Re: 29: error: ‘string’ does not name a type
Use std::string instead of the unqualified string.
Re: 29: error: ‘string’ does not name a type
Another option is to use the following
One contentions issue is whether or not you should use namespace declarations in code, personally I find them confusing and laserlight's method is the one I choose to use, especially when dealing with multiple namespaces.
Re: 29: error: ‘string’ does not name a type
The use of namespace in headers is not recommended so go for laserlight's suggestion.
Re: 29: error: ‘string’ does not name a type
Hi,
thanks, but why is it not recommended? What is the problem here?
Thanks,
J.
Re: 29: error: ‘string’ does not name a type
Namespaces are meant to be used to separate things to avoid name clashes. If you in the future need to use two or more namespaces that have name clashes and all your headers already set a namespace you can't resolve this without editing the headers. I.e. it defeats the purpose of namespaces and it's very bad in a maintainance perspective.
I guess that not using "use namespace" at all as GuOddian say is the safest way to go but it also requires some extra typing that can be saved to when it's actually needed (names actually clash)
Re: 29: error: ‘string’ does not name a type
Another way would be:
That way you only import the string.
Re: 29: error: ‘string’ does not name a type
Quote:
That way you only import the string.
That is still generally a Bad Thing in a header file.
Re: 29: error: ‘string’ does not name a type