Thread: Cant use as function...?

  1. #61
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    I can do for myself fine i was bringing it to his view that his program didn't work and i did punch it in i already fixed it. I am studying a book but hearing from other people is just as good. Their is no fundamental misunderstanding its topics i haven't learned yet. Saying i don't bother to do stuff myself is a assumption on your part. Quite irrelevant.

  2. #62
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Quote Originally Posted by Nathan the noob View Post
    I can do for myself fine i was bringing it to his view that his program didn't work and i did punch it in i already fixed it.
    Elysia is female

    Always keep in mind people will help you on this forum. Also if you use the "search" engine on this forum, you can find older posts to problems you may be encoutering, its always a good idea to check there first before asking a question.
    Double Helix STL

  3. #63
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I can do for [...] on your part. Quite irrelevant.
    His code does work. (Edit: I did it again! ^_^') You tried to use a function that takes a parameter without a parameter. You have ignored multiple requests for explanation.

    *shrug*

    Tell you what, if you can explain the parameters to 'std::accumulate' in your own words I'll be happy to offer an apology.

    Elysia is female
    O_o

    I think I've referred to "him" about [S]30[/S] 31 times...

    Soma
    Last edited by phantomotap; 02-18-2009 at 05:49 PM. Reason: ^_^

  4. #64
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    Code:
    #include <algorithm>
    #include <string>
    #include <iostream>
    #include <cctype>
    
    struct to_lower {     //Omg a class :D
      int operator() ( int ch )
      {
        return std::tolower ( ch );  //Return value of tolower :D
      }
    };
    
    struct to_upper {   //Omg a class thing :D
           int operator() ( int ch )
           {
               return std::toupper ( ch );
           }
    };
    
    int main()
    {
      std::string hello;
      std::cout<<"Hi Their, Please input anything you want:";
      getline(std::cin,hello);
      std::cout<<"Before: "<< hello <<'\n';
      std::transform(hello.begin(), hello.end(), hello.begin(), to_lower());
      std::cout<<"After conversion to lower: "<< hello <<'\n';
      std::transform(hello.begin(), hello.end(), hello.begin(), to_upper());
      std::cout<<"After conversion to upper: "<< hello <<'\n';
      getchar();
    }
    Got something to work
    Last edited by Nathan the noob; 02-18-2009 at 05:50 PM.

  5. #65
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    accumalate: Computing the sum of everything in a specific range

    Well i dont no its c++ term but something like that in the dictonary

    i was unaware i ignored anything :P


    edit: And heheh strange of you to leave a post assuming i can't do something for myself , Then asking me to make u happy so you'll apoligize << Forgot how to spell that
    Last edited by Nathan the noob; 02-18-2009 at 06:07 PM.

  6. #66
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    To help you understand your own comments:

    This is a struct:

    Code:
    struct Foo {
    int data;
    char letter;
    std::string name;
    };
    This is the same as a class:

    Code:
    class Foo {
    public: 
       Foo();
       ~Foo();
    
    private:
       int data;
       char letter;
       std::string name;
    };
    To verify, although they look similar a struct and a class operate differently. You can change a class into a struct by taking out the private keyword and the constructor/destructor. But the main difference is, by default, any data members of a class or private, for a struct they are public.
    Double Helix STL

  7. #67
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    So the struct is a class minus the private and its default is public. Il look up constructor/destructor.
    But you should never have all data members public as it goes against encapsualtion. Make them private and use functions, you could use getName() setName() for example to access them
    U said this a little back what is the purpose of hiding the values from the public and making the code longer?

    And a constructor doesnt exist in structs so doesnt that mean that structs have to has a return value?
    Last edited by Nathan the noob; 02-18-2009 at 06:11 PM.

  8. #68
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Nathan the noob View Post
    So the struct is a class minus the private and its default is public. Il look up constructor/destructor.


    U said this a little back what is the purpose of hiding the values from the public and making the code longer?

    And a constructor doesnt exist in structs so doesnt that mean that structs have to has a return value?
    The purpose of hiding the data from the public is that if you need/want to change how the data is stored (for purposes of efficiency, or just not screwing it up if the code turns out to be broken), then the people who use your class don't have to change anything, since they weren't using the internal data anyway.

    I don't know what you think you mean by "structs have to has a return value". Structs are data, not functions. Only functions can have return values.

    I don't know why Soma picked on accumulate, but you have shown by your posts that even though you have claimed to look up transform, you asked what the third parameter did. If you had looked up transform even a little bit, you would know what the third parameter was, and therefore why it was included. Hence our belief that you are not actually looking things up.

  9. #69
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    Chill...
    http://www.fredosaurus.com/notes-cpp...structors.html
    A constructor is similar to a function, but with the following differences.

    * No return type.
    * No return statement.

    So if a struct doesnt contain a constructor why doesnt it contain a return value?

    well first i looked up begin and end then transform and it didnt give me any indecation why a 2nd begin was added
    Last edited by Nathan the noob; 02-18-2009 at 07:02 PM.

  10. #70
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Because a struct isn't a function? A class isn't a function either, and notice how a class doesn't return anything either. Nor does an int return anything, or a double, or a std::string. No datatype returns anything, at any time.

    A class's constructor is almost a void function (a void function is a function that does something, but doesn't return a value), but the void keyword isn't used.

  11. #71
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    Just wondering cause swgh said that a struct is like a class but with out a constructor..
    Who needs a signature?

  12. #72
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    And a constructor doesnt exist in structs so doesnt that mean that structs have to has a return value?
    Yea... no fundamental misunderstanding at all.

    So if a struct doesnt contain a constructor why doesnt it contain a return value?
    This looks suspiciously like you didn't read either comment.

    Just wondering cause swgh said that a struct is like a class but with out a constructor..
    If you would stop this and go study you will learn. This "glance-guess-ask-repeat" nonsense of yours isn't educational.

    I don't know why Soma picked on accumulate
    I just needed a different function; that's what popped into my head.

    Soma

  13. #73
    Registered User
    Join Date
    Jun 2008
    Posts
    114
    I am reading i thought you ran off.
    If you insist on being bothersome.
    and now your poking at strings.

    Quote:
    So if a struct doesnt contain a constructor why doesnt it contain a return value?
    This looks suspiciously like you didn't read either comment.
    Its suspicious?

    I dislike your hostality towards me, Its quite pointless you wont PROVE anything.
    That seems to be what your trying to do.

    I see what you did now. I was under the impression that it was just to be a prick. Since i didn't no what it meant.

    prick: an obnoxious or contemptible person.
    Last edited by Nathan the noob; 02-18-2009 at 07:21 PM.

  14. #74
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by phantomotap View Post
    Elysia uses MSVC which, for whatever reason, doesn't "see" the possible ambiguity of the expression.
    So what might be wrong with the above transform? Why is it ambiguous and what can be done to make it unambiguous?
    I haven't used transform before, so I looked it up, put it into the compiler and fixed it so it would compile and work.

    Quote Originally Posted by Nathan the noob View Post
    Its suspicious?

    I dislike your hostality towards me, Its quite pointless you wont PROVE anything.
    That seems to be what your trying to do.

    I see what you did now. I was under the impression that it was just to be a prick. Since i didn't no what it meant.

    prick: an obnoxious or contemptible person.
    Take it easy now. Phantomotap is merely pointing out that you seem to lack some very basic understanding of how the language works, and suggests that you read books and/or tutorials until you get a better understanding before taking on projects doing something and start asking questions about why something doesn't work when it's a syntax error.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #75
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    So what might be wrong with the above transform?
    Nothing. Everything.

    Why is it ambiguous and what can be done to make it unambiguous?
    There are template overloads for both 'std::toupper' and 'std::tolower'.

    The same as always, force the compiler to use the overload you want.

    Phantomotap is merely [...] it's a syntax error.
    O_o

    I haven't seen any cooperation or diligence from him. I'm saying he needs to stop being stupid and lazy. I'm suggesting that he learn how to identify problems and research solutions himself because if he doesn't he will never be a programmer.

    Oh, and Nathan, just in case you still aren't getting it: tabstop and Elysia didn't ask you the questions they've asked for their health. Instead of thinking and answering those questions you just repeat the question as a statement or ignore them outright. So, yea, I think helping people who don't help themselves is beyond worthless.

    Soma
    Last edited by phantomotap; 02-19-2009 at 04:54 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM