Debugging error c2059

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pauldepstein@att.net

    Debugging error c2059

    I am adding to a large code base, and there is far too much code to
    paste it in its entirety. Here is some code that I added:

    struct MyStruct
    {
    MyStruct(const std::string& SomeString, const std::string&
    AnotherString)
    {

    }

    };

    MyStruct("SomeW ord", "AnotherWor d");


    Of course, the above code is not particularly useful. I was following
    the technique of making it as simple as possible to try and see what
    was triggering the error.

    The compiler complains about MyStruct("SomeW ord", "AnotherWor d");
    Referring to the line number where the above line occurs, it says
    error C2059: syntax error : 'string'
    Can anyone explain the probable cause of the error?

    Thank you all very much for your help.

    Paul Epstein
  • red floyd

    #2
    Re: Debugging error c2059

    pauldepstein@at t.net wrote:
    I am adding to a large code base, and there is far too much code to
    paste it in its entirety. Here is some code that I added:
    >
    struct MyStruct
    {
    MyStruct(const std::string& SomeString, const std::string&
    AnotherString)
    {
    >
    }
    >
    };
    >
    MyStruct("SomeW ord", "AnotherWor d");
    >
    >
    Of course, the above code is not particularly useful. I was following
    the technique of making it as simple as possible to try and see what
    was triggering the error.
    >
    The compiler complains about MyStruct("SomeW ord", "AnotherWor d");
    Referring to the line number where the above line occurs, it says
    error C2059: syntax error : 'string'
    Can anyone explain the probable cause of the error?
    >
    Thank you all very much for your help.
    >
    Yes. You didn't include <string>


    Correct code:

    #include <string>
    struct MyStruct
    {
    MyStruct(const std::string& SomeString, const std::string&
    AnotherString)
    {

    }

    };

    MyStruct("SomeW ord", "AnotherWor d");

    Comment

    • pauldepstein@att.net

      #3
      Re: Debugging error c2059

      On Mar 3, 12:10 pm, red floyd <no.s...@here.d udewrote:
      pauldepst...@at t.net wrote:
      I am adding to a large code base, and  there is far too much code to
      paste it in its entirety.  Here is some code that I added:
      >
      struct MyStruct
      {
         MyStruct(const std::string& SomeString, const std::string&
      AnotherString)
         {
      >
         }
      >
      };
      >
      MyStruct("SomeW ord", "AnotherWor d");
      >
      Of course, the above code is not particularly useful.  I was following
      the technique of making it as simple as possible to try and see what
      was triggering the error.
      >
      The compiler complains about MyStruct("SomeW ord", "AnotherWor d");
      Referring to the line number where the above line occurs, it says
      error C2059: syntax error : 'string'
      Can anyone explain the probable cause of the error?
      >
      Thank you all very much for your help.
      >
      Yes.  You didn't include <string>
      >
      Correct code:
      >
      #include <string>
      struct MyStruct
      {
          MyStruct(const std::string& SomeString, const std::string&
      AnotherString)
          {
      >
          }
      >
      };
      >
      MyStruct("SomeW ord", "AnotherWor d");- Hide quoted text -
      >
      - Show quoted text -
      Good guess but in fact I did use #include <string>
      Thanks a lot for trying to help though.

      Any more guesses?

      Paul Epstein

      Comment

      • pauldepstein@att.net

        #4
        Re: Debugging error c2059

        On Mar 3, 12:10 pm, red floyd <no.s...@here.d udewrote:
        pauldepst...@at t.net wrote:
        I am adding to a large code base, and  there is far too much code to
        paste it in its entirety.  Here is some code that I added:
        >
        struct MyStruct
        {
           MyStruct(const std::string& SomeString, const std::string&
        AnotherString)
           {
        >
           }
        >
        };
        >
        MyStruct("SomeW ord", "AnotherWor d");
        >
        Of course, the above code is not particularly useful.  I was following
        the technique of making it as simple as possible to try and see what
        was triggering the error.
        >
        The compiler complains about MyStruct("SomeW ord", "AnotherWor d");
        Referring to the line number where the above line occurs, it says
        error C2059: syntax error : 'string'
        Can anyone explain the probable cause of the error?
        >
        Thank you all very much for your help.
        >
        Yes.  You didn't include <string>
        >
        Correct code:
        >
        #include <string>
        struct MyStruct
        {
            MyStruct(const std::string& SomeString, const std::string&
        AnotherString)
            {
        >
            }
        >
        };
        >
        MyStruct("SomeW ord", "AnotherWor d");- Hide quoted text -
        >
        - Show quoted text -
        Correct code is actually:
        struct MyStruct
        {
        MyStruct(const std::string& SomeString, const std::string&
        AnotherString)
        {


        }



        };


        MyStruct YouHaveToGiveTh eMyStructVariab leAName("SomeWo rd",
        "AnotherWor d");

        Comment

        • Ian Collins

          #5
          Re: Debugging error c2059

          pauldepstein@at t.net wrote:
          On Mar 3, 12:10 pm, red floyd <no.s...@here.d udewrote:
          >Yes. You didn't include <string>
          >>
          >Correct code:
          >>
          >#include <string>
          >struct MyStruct
          >{
          > MyStruct(const std::string& SomeString, const std::string&
          >AnotherStrin g)
          > {
          >>
          > }
          >>
          >};
          >>
          >MyStruct("Some Word", "AnotherWor d");- Hide quoted text -
          >>
          >- Show quoted text -
          >
          Good guess but in fact I did use #include <string>
          Thanks a lot for trying to help though.
          >
          Any more guesses?
          >
          Guesses are all you're going to get. The posted code (with <string>) is
          fine.

          Try and form a complete example that gives the reported compiler error
          and post that.

          --
          Ian Collins.

          Comment

          Working...