Strange problem with string

T

Tony Johansson

Hello!

I have two very small classes(Head_1 and Head_2) see below and a very small
main.

I have run into a very strange problem. This program doesn't compile but if
I replace
the string type in class Head_2 with for example an int it compile.

If I put a comment out the class definition Head_1 it also compile.

I can't understand this so can anyone explain this to me. I would be very
glad.
#include "head..h"
int main()
{
Head_2 slask2;
return 0;
}

//This is Head..h
**************
class Head_1
{
public:
private:
};

class Head_2
{
public:
private:
string test;
};

Many thanks.

//Tony
 
M

marbac

Tony said:
Hello!

I have two very small classes(Head_1 and Head_2) see below and a very small
main.

I have run into a very strange problem. This program doesn't compile but if
I replace
the string type in class Head_2 with for example an int it compile.

If I put a comment out the class definition Head_1 it also compile.

I can't understand this so can anyone explain this to me. I would be very
glad.

Hi,

i found 2 problems in you program:

1.) You didn`t include the header for C++ string (it is not a "real
fundamental" datatype in c++)
2.) If you included it ... namespace std is missing

try

#include <string>

class Head_2
{
public:
private:
std::string test;
};

int main()
{
Head_2 slask2;
return 0;
}

or

#include <string>
using namespace std;

class Head_2
{
public:
private:
string test;
};

int main()
{
Head_2 slask2;
return 0;
}


regards marbac
 
M

marbac

Tony said:
Hello!

I have two very small classes(Head_1 and Head_2) see below and a very small
main.

I have run into a very strange problem. This program doesn't compile but if
I replace
the string type in class Head_2 with for example an int it compile.

If I put a comment out the class definition Head_1 it also compile.

I can't understand this so can anyone explain this to me. I would be very
glad.
#include "head..h"
int main()
{
Head_2 slask2;
return 0;
}

Hi,

i found 2 problems in your program:

1.) You didn`t include the header for C++ string (it is not a "real
fundamental" datatype in c++)
2.) If you included it ... namespace std is missing

try

#include <string>

class Head_2
{
public:
private:
std::string test;
};

int main()
{
Head_2 slask2;
return 0;
}

or

#include <string>
using namespace std;

class Head_2
{
public:
private:
string test;
};

int main()
{
Head_2 slask2;
return 0;
}


regards marbac
 

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,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top