What's the meaning of ::std::vector [duplicate] - c++

This question already has answers here:
What is the meaning of prepended double colon "::"?
(9 answers)
C++ : what is :: for?
(5 answers)
Closed 5 years ago.
I just saw in some DLib code, in a .cpp file a thing like that:
#include <stdio>
namespace {
using namespace std;
void foo() {
::std::vector<int> my_vector;
}
}
Is there a reason we specify ::std:: in front of our vector we imported from std already ?

Related

Global variable and extern [duplicate]

This question already has answers here:
Why must c++ statements be contained within functions?
(3 answers)
Code outside functions
(3 answers)
Can C++ have code in the global scope?
(1 answer)
Closed 1 year ago.
I have this three files
header.h
extern int global_var;
header.cpp
#include "header.h"
int global_var=50;
main.cpp
#include<iostream>
#include "header.h"
using namespace std;
global_var+=100;
int main(){
cout<<global_var;
}
when I run the prog error occurred :
global_var does not name a type
I know when I put global var inside main function work
but I want to know why this problem occurred

how can I use a function to print the name of args not use define In c++ [duplicate]

This question already has answers here:
generic way to print out variable name in c++
(6 answers)
Closed 1 year ago.
#include <iostream>
using namespace std;
#define debug(x) cout<<#x<<": "<<(x)<<endl;
int main() {
int a = 0;
debug(a)
return 0;
}
the output is: a:0
I want to print the name of variable like a
can I do it by a function not use define
i think the answers here can help you :
generic way to print out variable name in c++
and it seems the only way is using macro!

why using std::sqrt failed if I redefine the sqrt function? [duplicate]

This question already has answers here:
Can a declaration affect the std namespace?
(2 answers)
Why doesn't adding sqrt() cause a conflict in C++? [duplicate]
(1 answer)
Closed 2 years ago.
#include<iostream>
double sqrt(double);
int main()
{
double a = std::sqrt(4.0);
std::cout << a;
return 0;
}
double sqrt(double a)
{
return 1.0;
}
I know I declare the sqrt at first, but I use std::sqrt, it still call my own sqrt. why?
Search your code for a using namespace std; somewhere. Perhaps hidden in some other set of include files.

Why does `endl` working fine without namespace `std`? [duplicate]

This question already has answers here:
Why GCC allows calling this function without using its namespace first? [duplicate]
(1 answer)
Why does C++ parameter scope affect function lookup within a namespace?
(3 answers)
What is "Argument-Dependent Lookup" (aka ADL, or "Koenig Lookup")?
(4 answers)
Closed 4 years ago.
Case 1:
#include <iostream>
int main()
{
std::cout<<"Hello World"<<endl;
return 0;
}
Compiler give an error because endl need namespace std like std::endl.
case 2:
#include <iostream>
int main()
{
endl(std::cout);
return 0;
}
But, In second case without namespace std, endl working fine. Demo.
Why does endl working fine without namespace std?

Fatal Error in c++ while using local variables [duplicate]

This question already has answers here:
Where to get iostream.h
(3 answers)
Closed 7 years ago.
As am learning cpp tutorial
#include <iostream.h>
using namespace std;
int main()
{
//variable declaration
int a,b;
int c;
//actual initialization
a=10;b=20;
c=a+b;
cout<<c;
return 0;
}
my error
fatal error: iostream.h
Just change <iostream.h> to <iostream>
Reason is that .h header extensions were used for C includes but aren't used for C++ anymore.
In fact, you can actually use C libraries with .h it's just there isn't one for iostream since its C++ exclusive, hence the fatal error.