Professional Web Applications Themes

string class won't compile - Mac Programming

#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?...

  1. #1

    Default 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?
    Richard Guest

  2. #2

    Default 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

    JKop Guest

  3. #3

    Default 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)....
    Andre Guest

  4. #4

    Default 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>

    Miro Guest

  5. #5

    Default 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/ ]

    Mark Guest

  6. #6

    Default 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?
    Andre Guest

  7. #7

    Default 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/ ]

    Mark Guest

Similar Threads

  1. Invalid class string
    By r0ckster in forum ASP Components
    Replies: 1
    Last Post: March 7th, 01:50 PM
  2. [FLEX 2.0 SDK] error compile: Unable to resolve a class for factoryClass
    By Luca[M] in forum Macromedia Flex General Discussion
    Replies: 3
    Last Post: August 26th, 04:34 PM
  3. Add functions to the String Class
    By wrkoch in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: December 13th, 03:07 PM
  4. #25908 [NEW]: Class properties are added automatically (at compile time?)
    By kyle at putnamcabinets dot com in forum PHP Development
    Replies: 0
    Last Post: October 19th, 07:47 AM
  5. CDONTS - Invalid class string
    By Henry in forum ASP
    Replies: 1
    Last Post: June 30th, 04:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139