problem in mystring class

This is a discussion on problem in mystring class within the C++ Programming forums, part of the General Programming Boards category; well for the mystring function i will say: i wanted to be able to pass a string obj to the ...

  1. #16
    Banned
    Join Date
    Nov 2007
    Posts
    678
    well for the mystring function i will say:
    i wanted to be able to pass a string obj to the function and made the *this default so it would work both ways. eg:
    Code:
    sting std_str = "ABC";
    mystring str;
    //like this
    str.lower_case(std_str);
    //and on its own like this
    str.lower_case();
    but i have changed my functions, they don't take any arguments now and modify *this and return it as well.

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    Bad. If you want a lower_case that can take another string object (which you really shouldn't need), make it static. This gives the effect that it's available in a namespace like mystring::lower_case and not part of the object itself.
    To be better, you could create a namespace named String and put that function there instead.
    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.

  3. #18
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Oh My GOD ! ! !
    I Love You Elysia! Thanks a lot
    The MSVC is doing all the completions etc. stuff with Qt API now
    And for building I can still use the same old command line method (until I find a way with MSVC).

  4. #19
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    Quote Originally Posted by manav View Post
    And for building I can still use the same old command line method (until I find a way with MSVC).
    I seriously recommend against it.
    You are breaking lots of stuff in the code. If your code throws, it won't work as it should, for example (since you have disabled C++ exception handling!!). And who knows what else you've broken by compiling manually?
    At least set up your project as it should compile and copy the command line from the GUI. At least do that. Microsoft's compiler is a complex beast that wasn't really meant to be used in CLI I bet, since they did it overly complex.
    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.

  5. #20
    Banned
    Join Date
    Nov 2007
    Posts
    678
    me too don't have any idea about good/bad command line options for cl but these are the options that i am using:
    Code:
    DEFINES       = -DUNICODE -DQT_LARGEFILE_SUPPORT -DWIN32 -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT
    CFLAGS        = -nologo -Zm200 -GS -Od -ZI -Gm -MDd -W3 $(DEFINES)
    CXXFLAGS      = -nologo -Zm200 -GS -Od -ZI -Gm -MDd -GR -EHsc -W3 $(DEFINES)
    i hope somebody who understands cl can tell how good/bad these options are!

    EDIT: the above are for DEBUG mode.
    here are RELEASE mode options:
    Code:
    DEFINES       = -DUNICODE -DQT_LARGEFILE_SUPPORT -DWIN32 -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT
    CFLAGS        = -nologo -Zm200 -GS -O1 -MD -DNDEBUG -W3 $(DEFINES)
    CXXFLAGS      = -nologo -Zm200 -GS -O1 -MD -DNDEBUG -GR -EHsc -W3 $(DEFINES)

  6. #21
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    Huh? None of those are cl commands.
    They all begin with "/" contrary to the linux standard of "-" which is really annoying rather than the "/" in my opinion.
    And you aren't even using highest warning level, which is another reason you should avoid your manual compile alternative.
    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.

  7. #22
    Banned
    Join Date
    Nov 2007
    Posts
    678
    no tested it. cl understands options starting with the hyphen.

  8. #23
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    Sneaky Microsoft
    Doesn't mention such a thing in the docs.

    But do say, when it's multi-platform, they always introduce this unneccesary and stupid stuff. Using a makefile for compiling the project is stupid as you lose every functionality in the project settings.

    EDIT:
    Try this guide as well:
    http://ldmartin68.com/QTSetup4VSNET.html
    But ignore the advice about disabling precompiled headers.
    Last edited by Elysia; 04-10-2008 at 06:52 AM.
    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.

  9. #24
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Don't make the function static. Make it a free function as anon mentioned and don't derive from std::string at all. There's no reason to, it just creates unnecessary complexity. lower_case(my_str) is just as easy to call as my_str.lower_case().

  10. #25
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Daved View Post
    Don't make the function static. Make it a free function as anon mentioned and don't derive from std::string at all. There's no reason to, it just creates unnecessary complexity. lower_case(my_str) is just as easy to call as my_str.lower_case().
    Not to mention that it's actually more flexible: You can do my_str3 = lower_case(my_str1 + my_str2);

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #26
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Well, I think you could do my_str3 = (my_str1 + my_str2).lower_case() too, but I don't really want to argue for that syntax.

  12. #27
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Daved View Post
    Well, I think you could do my_str3 = (my_str1 + my_str2).lower_case() too, but I don't really want to argue for that syntax.
    Ok, it's not something I would write, but I give you that it would be valid thing to do - but most people wouldn't even understand what it does...

    Edit: It's when I see things like that, that I remember that I don't know C++ well enough - although I don't want to write code like that, I would at least want to know that it can be done... ;-)

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #28
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    Quote Originally Posted by matsp View Post
    Not to mention that it's actually more flexible: You can do my_str3 = lower_case(my_str1 + my_str2);

    --
    Mats
    Obviously it might have its uses, but I don't recommend placing such a function inside the mystr class. It's not part of the class because it only modifies and returns the data from the argument, so it may well be placed outside the class and using public methods in the class for better encapsulation.
    And what better place to put than inside a namespace such as String, where all your string functions are gathered?
    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.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 08:10 AM
  3. Problem with friend class declaration in a namespace
    By Angus in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2008, 12:29 PM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  5. Replies: 3
    Last Post: 12-03-2001, 12:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21