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?
Re: string class won't compile
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
Re: string class won't compile
JKop <NULL> wrote in news:1EfLc.5079$indigo.ie:
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)....
Re: string class won't compile
In article <35.177.135>,
Andre Kostur <net> wrote:
>
> 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)....[/ref]
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>
Re: string class won't compile
[...]
>
>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)....[/ref]
Bad symbol lookup or ambiguity. Sure? Interesting!!!
Mark
--
[ C++ FAQ: http://www.parashift.com/c++-faq-lite/ ]
Re: string class won't compile
Mark <com> wrote in
news:com:
>>
>>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)....[/ref]
>
> Bad symbol lookup or ambiguity. Sure? Interesting!!![/ref]
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?
Re: string class won't compile
On Wed, 21 Jul 2004 15:43:33 GMT, Andre Kostur <net>
wrote:
[...]
>
>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?[/ref]
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/ ]