Thread: example of ::

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    5

    Lightbulb example of ::

    Hello all, I am studying c++. As we know :: scope resolution operator is being used when there r 2 variable declarations: one inside main, other outside main (variable name is same in both).
    But I don't understand in which cases same variable name is required. why don't we use different variable names and avoid using ::

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by kapilh
    As we know :: scope resolution operator is being used when there r 2 variable declarations: one inside main, other outside main (variable name is same in both).
    But I don't understand in which cases same variable name is required. why don't we use different variable names and avoid using ::
    Imagine if you are using a library written by someone else. The library interface might have names (of functions, classes, etc, not necessarily just variables) that make sense for your project, so you use them too, but for your own purposes. The solution here is for the library to have the names in the library's namespace, and your project's names are in your namespace. This way, the names can be used unqualified within the appropriate context, and qualified (with the scope resolution operator coming into play) as needed.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    5

    Exclamation tnx,reply

    Quote Originally Posted by laserlight View Post
    Imagine if you are using a library written by someone else. The library interface might have names (of functions, classes, etc, not necessarily just variables) that make sense for your project, so you use them too, but for your own purposes. The solution here is for the library to have the names in the library's namespace, and your project's names are in your namespace. This way, the names can be used unqualified within the appropriate context, and qualified (with the scope resolution operator coming into play) as needed.
    Hi, I appreciate your efforts. However, I am unable to understand ur post. I am new to programming and c++, so not aware of namespace etc. and project too. I will appreciate if you could give me an example (with small code) of variables or likewise.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Ah. I suggest that you don't worry about this for now and just keep learning C++. I could certainly give you an example, but it will probably lead to more questions, and I have no intention of writing a tutorial here.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Feb 2013
    Posts
    5

    its ok

    Quote Originally Posted by laserlight View Post
    Ah. I suggest that you don't worry about this for now and just keep learning C++. I could certainly give you an example, but it will probably lead to more questions, and I have no intention of writing a tutorial here.
    ahha, I understand...thanks.


    hi laser light, I just started c++, I have not made/study any project so far. So I want to study sample project in C and sample project in C++ (with designing phase included) to feel the importance of OOP.

    Regards

  6. #6
    Registered User
    Join Date
    Feb 2013
    Posts
    5
    Could you get me sample projects so that i can understand how projects developed, and can made some projects to have hands-on experience.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    Goto sourceforge.net, download the source for some project(s) of interest, do lots of reading.
    Maybe join the developer mailing lists to see how the project is managed (how code is submitted, tested, reviewed etc).
    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.

Popular pages Recent additions subscribe to a feed