Thread: class string

  1. #1
    Registered User
    Join Date
    Mar 2019
    Posts
    51

    class string

    When we use class string, we create an string object. what is about its member functions? We don't call them except the function that overload operator <<>>

    So, my confusion is, how do, and where if called , the other member functions are called?

    Or they are called automatically? Is this a way?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,408
    Seriously, RTFM -> <string> - C++ Reference
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2019
    Posts
    51
    Quote Originally Posted by Salem View Post
    Seriously, RTFM -> <string> - C++ Reference
    Sir, I'm beginner in C++. Can you please tell me that if string member functions are executed automatically? Because when we create an string object. I see not a call of member function.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    3,652
    object.memberFunction is the normal way to call memberFunction.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    May 2019
    Posts
    209
    @rm82co

    Can you please tell me that if string member functions are executed automatically?
    The constructor is a function "called automatically" in the sense that it is part of construction. Study on the subject of constructors and destructors.

    The destructor is a function "called automatically" when the string falls from scope (is otherwise deleted as the member of another class/struct).

    When using operators like << or + or +=, these are actually ways of calling functions, in this case operator functions. I wouldn't say this is "automatic", but it might fit what you're thinking. They are not really "automatic" because these operators are functions in classes like string, but you might be thinking of them as automatic merely because the syntax is not that of a member function call like s.c_str(); It would be an error, really, to think they are automatic. This is also true of the assignment operator "=".

  6. #6
    Registered User
    Join Date
    Mar 2019
    Posts
    51
    Quote Originally Posted by Niccolo View Post
    @rm82co



    The constructor is a function "called automatically" in the sense that it is part of construction. Study on the subject of constructors and destructors.

    The destructor is a function "called automatically" when the string falls from scope (is otherwise deleted as the member of another class/struct).

    When using operators like << or + or +=, these are actually ways of calling functions, in this case operator functions. I wouldn't say this is "automatic", but it might fit what you're thinking. They are not really "automatic" because these operators are functions in classes like string, but you might be thinking of them as automatic merely because the syntax is not that of a member function call like s.c_str(); It would be an error, really, to think they are automatic. This is also true of the assignment operator "=".
    Thank you. Actually I know those are functions and not automatically called. Because these operators in itself are functions. Anyway up have been told about constructors. I think my reply exist in the concept of constructors. Thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String Class
    By Bitphire in forum C++ Programming
    Replies: 6
    Last Post: 02-24-2005, 12:54 PM
  2. The String Class
    By sundeeptuteja in forum C++ Programming
    Replies: 3
    Last Post: 05-31-2003, 11:43 AM
  3. string class
    By Star Lancer in forum C++ Programming
    Replies: 1
    Last Post: 04-28-2003, 03:08 AM
  4. String Class
    By JBravo in forum C++ Programming
    Replies: 8
    Last Post: 02-24-2002, 06:38 AM
  5. String Class
    By CanadianOutlaw in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2001, 01:33 PM

Tags for this Thread