Thread: Assignment working but have questions

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by manasij7479 View Post
    Well, I declare everything written by me in a separate namespace ...and use namespace std globally.
    (Because I use the standard library *much* more frequently than totally homebrew code...)
    This is still not very good. If you a function or variable named "array", it will hide the one from the standard library.

    Using namespace statements are nice, but they have their drawbacks. Simple using statements have the same drawbacks, but they affect lesser scopes.
    There is nothing wrong with using them, as long as you know what they do and what problems they might cause. It is up to you to decide whether that is acceptable or not.
    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.

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by Elysia View Post
    This is still not very good. If you a function or variable named "array", it will hide the one from the standard library.
    Why ?
    If I have my array inside namespace foo,
    I can use my array as foo::array outside it, and when I need std::array inside namespace foo, I would specify it as such.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by manasij7479 View Post
    Why ?
    If I have my array inside namespace foo,
    I can use my array as foo::array outside it, and when I need std::array inside namespace foo, I would specify it as such.
    Imagine that someday, in your code, you want to use std::array. Since you typically use "using namespace std," you simply type "array."
    But since you are in the namespace foo, you get foo::array instead, and if the classes are not dissimilar, it might just compile and you will get incorrect code!
    Hence why it might not be so good.
    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.

  4. #4
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by Elysia View Post
    Imagine that someday, in your code, you want to use std::array. Since you typically use "using namespace std," you simply type "array."
    But since you are in the namespace foo, you get foo::array instead, and if the classes are not dissimilar, it might just compile and you will get incorrect code!
    Hence why it might not be so good.
    I don't use namespace std in the implementation files related to stuff within namespace foo.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ItemArray assignment not working as expected
    By Dragoon_42 in forum C# Programming
    Replies: 1
    Last Post: 01-28-2010, 03:11 PM
  2. Replies: 3
    Last Post: 04-26-2009, 08:54 AM
  3. Replies: 9
    Last Post: 03-30-2009, 04:09 AM
  4. Pointer assignment not working
    By coderCPP1981 in forum C Programming
    Replies: 6
    Last Post: 06-20-2008, 06:59 AM
  5. three questions about hw assignment
    By jlmac2001 in forum C++ Programming
    Replies: 8
    Last Post: 09-11-2003, 01:55 PM