473,320 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

string class won't compile

#include <string>
using std::string;
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>

void My Function(string ParameterOne, string ParameterTwo)
{
int i, j;
string MyString = "hello";
}
This chokes on the last line and says "error: 'string' undeclared (first
use in this function). What am I doing wrong?
Jul 22 '05 #1
7 1213
Made 3 changes:

1) Got rid of #include <gmp.h>

2) Fixed typo in function definition

3) Put in "main".
The following should and does compile:
#include <string>

using std::string;

#include <stdio.h>
#include <stdlib.h>

//#include <gmp.h>

void MyFunction(string ParameterOne, string ParameterTwo)
{
int i, j;
string MyString = "hello";
}

int main()
{

}
-JKop

Jul 22 '05 #2
JKop <NU**@NULL.NULL> wrote in news:1E*****************@news.indigo.ie:
Made 3 changes:

1) Got rid of #include <gmp.h>

2) Fixed typo in function definition

3) Put in "main".
The following should and does compile:
#include <string>

using std::string;

#include <stdio.h>
#include <stdlib.h>

//#include <gmp.h>


Stylistic point to consider....

I'd move all of your using declarations after _all_ includes. If you
don't, you may inadvertantly bring in a bad symbol lookup (or
ambiguity)....
Jul 22 '05 #3
In article <Xn*******************************@207.35.177.135> ,
Andre Kostur <nn******@kostur.net> wrote:
JKop <NU**@NULL.NULL> wrote in news:1E*****************@news.indigo.ie:
Made 3 changes:

1) Got rid of #include <gmp.h>

2) Fixed typo in function definition

3) Put in "main".
The following should and does compile:
#include <string>

using std::string;

#include <stdio.h>
#include <stdlib.h>

//#include <gmp.h>


Stylistic point to consider....

I'd move all of your using declarations after _all_ includes. If you
don't, you may inadvertantly bring in a bad symbol lookup (or
ambiguity)....


I disagree. I find that

#include <string>
using std::string

#include <vector>
using std::vector

#include <...>
using ...

much much more legible than what you propose, and the risk of ambiguity is low
(so low, in fact, that I have never run into this problem, and I use STL and
boost heavily).

meeroh

--
If this message helped you, consider buying an item
from my wish list: <http://web.meeroh.org/wishlist>

Jul 22 '05 #4

[...]

The following should and does compile:
#include <string>

using std::string;

#include <stdio.h>
#include <stdlib.h>

//#include <gmp.h>


Stylistic point to consider....

I'd move all of your using declarations after _all_ includes. If you
don't, you may inadvertantly bring in a bad symbol lookup (or
ambiguity)....


Bad symbol lookup or ambiguity. Sure? Interesting!!!

Mark
--
[ C++ FAQ: http://www.parashift.com/c++-faq-lite/ ]

Jul 22 '05 #5
"Miro Jurisic" <ma****@meeroh.org> wrote in message
news:ma**************************@senator-bedfellow.mit.edu...
I disagree. I find that

#include <string>
using std::string

#include <vector>
using std::vector

#include <...>
using ...

much much more legible than what you propose, and the risk of ambiguity is low (so low, in fact, that I have never run into this problem, and I use STL and boost heavily).


Beauty is in the eye of the beholder. I prefer this order: application
headers, standard headers, using declarations/directives. The elimination
of potential ambiguities/hidden dependencies is an added bonus.

--
David Hilsee
Jul 22 '05 #6
Mark <ma**********@hotmail.com> wrote in
news:jr********************************@4ax.com:

[...]

The following should and does compile:
#include <string>

using std::string;

#include <stdio.h>
#include <stdlib.h>

//#include <gmp.h>


Stylistic point to consider....

I'd move all of your using declarations after _all_ includes. If you
don't, you may inadvertantly bring in a bad symbol lookup (or
ambiguity)....


Bad symbol lookup or ambiguity. Sure? Interesting!!!


If you have an unqualified identifier in a subsequent header file, which
namespace does it come from? Let's assume:

/// a.h

extern void fn(string str);

/// a.cpp

#include <string>
using std::string;

#include "a.h"

void fn(string str)
{
}

/// b.cpp

#include <customstring>
using customstring::string;

#include "a.h"

void bfn()
{
fn("");
}

What happens in b.cpp?
Jul 22 '05 #7
On Wed, 21 Jul 2004 15:43:33 GMT, Andre Kostur <nn******@kostur.net>
wrote:

[...]
Bad symbol lookup or ambiguity. Sure? Interesting!!!


If you have an unqualified identifier in a subsequent header file, which
namespace does it come from? Let's assume:

/// a.h

extern void fn(string str);

/// a.cpp

#include <string>
using std::string;

#include "a.h"

void fn(string str)
{
}

/// b.cpp

#include <customstring>
using customstring::string;

#include "a.h"

void bfn()
{
fn("");
}

What happens in b.cpp?


Point taken. As I understand the example, it boils down to which
namespace, hence the ambiguity.

Mark
--
[ C++ FAQ: http://www.parashift.com/c++-faq-lite/ ]

Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
21
by: M D | last post by:
You know how you assume you know until you find out you don't know. Well, I typed into a function definition "..., new String("")). I know what I want. Everyone reading this knows what I want....
8
by: Tony H | last post by:
Is there a way to read an MFC serialized class containing CStrings, ints, and doubles using a CLR-based class? Specifically, to get CString into System::String? Bye the Bye, is System:: String...
10
by: Peter Oliphant | last post by:
Is there a way of defining a method in a base class such that derived classes will call their own version, EVEN if the derived instance is referred to by a pointer to the base class? Note that the...
19
by: Jaime Stuardo | last post by:
Hi all.. I have created a business logic component that is used from my ASP.NET webform. It works, but connection string to the database is hard coded, as in this method : public DataSet...
10
by: mattias.k.nyberg | last post by:
So Im trying to learn to program with C#. And I have this question about why the string array won't work in the first class but it does in the second. To me it looks like they do the exact same...
10
by: John A Grandy | last post by:
Say I have Class1 which contains static Class2 var1 = new Class2(); Is Class2 constructor code only executed if var1 is referenced in the code-execution path ? Or is Class2 constructor code...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
3
by: Kevin Frey | last post by:
I am porting Managed C++ code from VS2003 to VS2005. Therefore adopting the new C++/CLI syntax rather than /clr:oldSyntax. Much of our managed code is concerned with interfacing to native C++...
9
by: Zootal | last post by:
The following code will compile. I have one line commented out because it won't compile. Why can I not do this: //set<string>::iterator iterator = s->begin(); Why do I have to deference the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.