Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть C++ for Beginners Video 05 - Blocks, Scopes, and the Scope Resolution Operator

  • Yeti Code Camp
  • 2019-12-24
  • 264
C++ for Beginners Video 05 - Blocks, Scopes, and the Scope Resolution Operator
  • ok logo

Скачать C++ for Beginners Video 05 - Blocks, Scopes, and the Scope Resolution Operator бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно C++ for Beginners Video 05 - Blocks, Scopes, and the Scope Resolution Operator или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку C++ for Beginners Video 05 - Blocks, Scopes, and the Scope Resolution Operator бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео C++ for Beginners Video 05 - Blocks, Scopes, and the Scope Resolution Operator

In this 5th video of the C++ for beginners series we will be going over the concept of scopes, blocks, and namespaces within C++, as well as using the Scope Resolution Operator '::' .

This text provides additional explanation to compliment the material covered in the video.

Scope

The first topic I want to cover, is of the concept of a scope.

The noun form of scope is generally defined as "an extent, or range, of which something can be viewed or acted upon".

The gist of this definition is that the term scope implies a range, extent, or limit of something.

In computer science the definition is more narrowly defined to mean an association of a name to an entity, in our case a block.

An generic example of this is a variable within the region of a computer program where the binding is valid, or basically where the name can be used to refer to the entity.

A region within which, where a variable's name, or binding is valid is often referred to as a block. A block then, is the limit, or extent of a scope.

A block limits the visibility of the variable to within itself, whereas in other parts of the program, the name may refer to a different entity entirely. In other words, a variables visibility, or use, is limited to the block within which they are declared, or within the scope of a block. The same holds true for functions.

For now we will focus on variables.

For our purposes, we can think of a variable's scope as falling within two main categories:

1. Local Variables
2. Global Variables

Local Variables

Variables defined within a function or block are said to be local to those functions (or blocks).

• Code placed inside curly braces ‘{‘ and ‘}’ is considered to be inside a block.
• Local variables exist only within the block in which they are declared.

A function can also be considered a block as it utilizes curly braces, as do loops, if statements, and other structures.

Consider the main() function as a block since variables declared within main are considered local to main. The same with a loop, think of the iterator inside of a for loop for instance.

While local variables normally can not be accessed or used outside of that block, there are exceptions which we will cover shortly.

Global Variables

• As the name suggests, Global variables can be accessed from any part of the program.
• Global variables are usually declared at the top of a program.
• Global variables need to be declared outside of all of the functions and blocks.
• Global variables can be accessed from any portion of the program.

Scope Resolution Operator

The scope resolution operator, represented by a double colon '::' is a way to clarify the scope of an object. We have already seen its use while utilizing the objects within the standard namespace, such as cin, cout, and endl.

Recall we use the format std::cout and std::endl to access these objects. This is to show we want to use the cout, cin, and endl within the standard namespace. Your program could even have other cin cout, and endl identifiers contained within other namespaces.

So in essence namespaces are useful to avoid "naming collisions", or having two variables, functions, or objects with the same name conflict with one another. The scope resolution operator allows us a way to reference, or resolve which namespace, or more specifically what scope we are referring to.

A good example is your home address for instance. You may live at 123 Main Street, but if you give someone your address in another town, and don't inform them what town (or namespace) you live in, they will have a hard time finding your house.

However, if you give your address to someone within your town, they will probably have no trouble. This is because they are within the same namespace as you. In other words you are both with the same scope. Your address is unique inside your town's scope, much like a variable name is unique within a function.

But if instead your friend lives in another town they are part of a different scope. He/she may even have the same address as you do, but it is unique within their town. So they are essentially part of a different scope than you are, which can also be thought of as a namespace.

So a namespace is basically a way to provide a scope for a variable, function, or some other item, and define where it lives (or is located).

In C++ any name that is not defined within a block (class, function, or a namespace) is considered to be part an implicit namespace called the global namespace or the global scope. The main function in our program is thus within the global scope (or namespace).

In the video I show examples of the above topics.

Project files can be found at: https://github.com/YetiCodeCamp

Companion Website: https://yeticodecamp.github.io/cpp-fo...

Follow YetiCodeCamp on Twitter:   / yeticode  

C++, #Cpp #Tutorial for #Beginners

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]