default object argument

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anil Mamede

    default object argument

    Can i do this:

    function(std::s tring = "Hello, world"); ?

    If not, is there other way that i can because my compiler (gcc 3.2) is
    giving an error;

    Thanks,
    Anil Mamede



  • Nils Petter Vaskinn

    #2
    Re: default object argument

    On Thu, 04 Sep 2003 11:06:25 +0100, Anil Mamede wrote:
    [color=blue]
    > Can i do this:
    >
    > function(std::s tring = "Hello, world"); ?
    >
    > If not, is there other way that i can because my compiler (gcc 3.2) is
    > giving an error;[/color]

    And what was the errot message then? Did you read it?

    function (std::string s = "Hello, world");

    hth

    --
    NPV
    "Linux is to Lego as Windows is to Fisher Price." - Doctor J Frink

    Comment

    • Big Brian

      #3
      Re: default object argument

      > Can i do this:[color=blue]
      >
      > function(std::s tring = "Hello, world"); ?
      >
      > If not, is there other way that i can because my compiler (gcc 3.2) is
      > giving an error;
      >
      > Thanks,
      > Anil Mamede[/color]

      It would be helpful if you said what the error was. You may even be
      able to figure it out yourself if you read the error.

      But, yes you can provide a default argument for function parameters of
      type std::string with gcc. The following compiles with gcc


      #include <iostream>
      #include <string>

      void f(std::string s = "test" )
      {
      std::cout << s << std::endl;
      }

      int main(int argc, char* argv[])
      {
      f();
      f("BLA");

      return 0;
      }


      when executed, it produces the following

      test
      BLA

      Comment

      • Sumit Rajan

        #4
        Re: default object argument

        [color=blue]
        >
        > Try this:
        >
        > function(std::s tring("Hello, World"));
        >
        > Sumit.[/color]

        Sorry. Please disregard my earlier post. I had misunderstood your query.

        Regards,
        Sumit.

        Comment

        Working...