string class and vc++.wank :)

J

John Swan

I dont think I have ever been as dissappointed, frustrated or bewildered in
all of my life.
The problem, well take this class definition:
#ifndef __DATA

#define __DATA

#pragma once

#include <iostream>

#include <string>

class Data

{

public:

Data(void);

~Data(void);

private:

int XAxis, YAxis, StartFrom;



};

#endif

This will compile quite happily. However, if I were to add a string called
s1 it wont compile.
#ifndef __DATA

#define __DATA

#pragma once

#include <iostream>

#include <string>

class Data

{

public:

Data(void);

~Data(void);

private:

int XAxis, YAxis, StartFrom;

string s1;

};

#endif

When I try to compile the above code I get: Error C2146, c2501 twice.
Can anyone please tell me what I am doing wrong please?????

I really am glad this is a small project. I am going to develop using QT.
Multi platform and a dream in comparison. Apparently.

Opions please.

Cheers
John
 
D

David Wilkinson

John said:
I dont think I have ever been as dissappointed, frustrated or bewildered in
all of my life.
The problem, well take this class definition:
#ifndef __DATA

#define __DATA

#pragma once

#include <iostream>

#include <string>

class Data

{

public:

Data(void);

~Data(void);

private:

int XAxis, YAxis, StartFrom;



};

#endif

This will compile quite happily. However, if I were to add a string called
s1 it wont compile.
#ifndef __DATA

#define __DATA

#pragma once

#include <iostream>

#include <string>

class Data

{

public:

Data(void);

~Data(void);

private:

int XAxis, YAxis, StartFrom;

string s1;

};

#endif

When I try to compile the above code I get: Error C2146, c2501 twice.
Can anyone please tell me what I am doing wrong please?????

I really am glad this is a small project. I am going to develop using QT.
Multi platform and a dream in comparison. Apparently.

Opions please.

Cheers
John

John:

std::string s1;

Also, don't use double underscores. They are reserved for the
implementation.

HTH,

David Wilkinson
 
J

John Swan

Thanks.

Have I done something silly and not included a namespace or something?????

In the examples that are provided in the MSDN, you do not need to that.

I must admit - I have not done any form of coding in a few years but feel
that managed.net is, well - non standard. Would you agree?

Thanks
John
 
N

Nishant Sivakumar

Have I done something silly and not included a namespace or
You can add :

using namespace std;

....and avoid having to do std::string all the time. If you don't want to put
that globally, you can put the using namespace within the block where you
want to use the string class.
 
A

adebaene

John Swan a écrit :
Thanks.

Have I done something silly and not included a namespace or something?????
All standard library objects (those defined in the headers without a
..h) are in the namespace "std". Other posters have provided more
backgournd on namespaces and how to use them...
In the examples that are provided in the MSDN, you do not need to that.
Unfortunately (or not, depending on your point of view), a lot of
samples are not compilable "as-is". Rather, they are made short and
concentrate on the problem/point they intend to demonstrate.
I must admit - I have not done any form of coding in a few years but feel
that managed.net is, well - non standard. Would you agree?
Your code is standard compliant, non-managed C++ and has nothing to do
with .NET. It would be the same thing with GCC or any other decently
conforming compiler.

If you've got a different behavior on another system, then your
compiler on that system is not conformant.

Concerning "standardeze level" of managed C++ or C++/CLI, it may be a
debate but the point is moot in your case, since you're writing native,
standard C++.

Arnaud
MVP - VC
 
J

John Swan

Thanks lads.
Managed to do more tonight then, well, a while. :)

Now - another easy one for you.
How do you convert a std:String to a System:String????


Thanks a lot guys.

John


John Swan a écrit :
Thanks.

Have I done something silly and not included a namespace or something?????
All standard library objects (those defined in the headers without a
..h) are in the namespace "std". Other posters have provided more
backgournd on namespaces and how to use them...
In the examples that are provided in the MSDN, you do not need to that.
Unfortunately (or not, depending on your point of view), a lot of
samples are not compilable "as-is". Rather, they are made short and
concentrate on the problem/point they intend to demonstrate.
I must admit - I have not done any form of coding in a few years but feel
that managed.net is, well - non standard. Would you agree?
Your code is standard compliant, non-managed C++ and has nothing to do
with .NET. It would be the same thing with GCC or any other decently
conforming compiler.

If you've got a different behavior on another system, then your
compiler on that system is not conformant.

Concerning "standardeze level" of managed C++ or C++/CLI, it may be a
debate but the point is moot in your case, since you're writing native,
standard C++.

Arnaud
MVP - VC
 

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

Top