head file inclusions

G

Gary Wessle

Hi

in a header file I have

********************************
#ifndef READ_DATA_H
#define READ_DATA_H


#include <string>
using string::string; <<---- line 6
********************************

but when I $make I get error in reference to using string::string
fred@debian:~/myPrograms/common$ make
g++ -c -o read_data.o read_data.cpp
read_data.h:6: error: 'string' has not been declared
read_data.h:6: error: expected nested-name-specifier before 'string'
read_data.h:6: error: 'string' has not been declared
 
V

Victor Bazarov

Gary said:
Hi

in a header file I have

********************************
#ifndef READ_DATA_H
#define READ_DATA_H


#include <string>
using string::string; <<---- line 6

Did you mean

using std::string;

??

BTW, 'using' declarations and directives in the global scope are
really *not* recommended in a header. Why do you think you need
it?
********************************

but when I $make I get error in reference to using string::string
fred@debian:~/myPrograms/common$ make
g++ -c -o read_data.o read_data.cpp
read_data.h:6: error: 'string' has not been declared
read_data.h:6: error: expected nested-name-specifier before 'string'
read_data.h:6: error: 'string' has not been declared

V
 
G

Gary Wessle

Victor Bazarov said:
Did you mean

using std::string;

??

BTW, 'using' declarations and directives in the global scope are
really *not* recommended in a header. Why do you think you need
it?

because I need to use "string" in the argument of one of the public
member functions as below

#ifndef READ_DATA_H
#define READ_DATA_H


#include <string>
using std::string;


class read_data
{
int number_of_lines;
string file_name;

public:
read_data(string); //<<-------- this
~read_data();
int get_number_of_lines();

};


#endif
 
I

Ian Collins

Gary said:
because I need to use "string" in the argument of one of the public
member functions as below
No, you don't. You just type std::string. Never put using directives
in headers!
 
K

Kai-Uwe Bux

Gary said:
because I need to use "string" in the argument of one of the public
member functions as below

You don't need the using directive.
#ifndef READ_DATA_H
#define READ_DATA_H


#include <string>
using std::string;

Ditch the using thing.
class read_data
{
int number_of_lines;
string file_name;

public:
read_data(string); //<<-------- this

Do:

read_data( std::string );
 
V

Victor Bazarov

Kai-Uwe Bux said:
You don't need the using directive.


Ditch the using thing.


Do:

read_data( std::string );

Or better:

read_data(std::string const&);

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top