In C++ if no user defined constructor is provided for a class the compiler automatically provides a implicit default constructor.
An implicit default constructor is equivalent to a default constructor with no parameters and no body ?
So what is the use of a implicit default constructor provided by the compiler, if it is not going to do anything ?
User Profile
Collapse
-
carbon started a topic C++ What is the use of a implict default constructor provided by the comiler ?in CC++ What is the use of a implict default constructor provided by the comiler ?
-
Well correct me if I'm wrong. But I think it's a undefined behavior.
Between two sequence points a variable must not be modified more than once.
To understand what's going on you have to learn about undefined-behavior and sequence-points.
Checkout this question on stackoverflow.c om. -
I have cleared my doubts.
Cv-qualifiers like const apply to whatever is to the left of them, unless there is nothing, in which case they apply to the right.
The above code works because here, r has been declared a reference to a constant pointer that is pointing to a character type.Code:char* const &r = a;
The above code doesn't work as here, r...Code:const char* &r = a;
Leave a comment:
-
Need help c++ reference.
Code:int main(){ char const &rr = 'x'; //works //const char &rr = 'x'; works char a[5] = "Hi!"; char* const &r = a; //works //const char* &r = a; doesn't works std::cout << rr << std::endl; std::cout << r[2] << std::endl; system("pause"); return 0; } -
"When using namespace A is inside main(), it applies only to main(). Therefore, the get_value() is the one in A."
But according to cpp standard members will be introduced into the enclosing namespace which in this case is global namespace.
From Cpp 98 standard ..
7.3.4 : A using-directive specifies that the names in the nominated namespace can be used in the scope in which the usingdirective
appears...Leave a comment:
-
Sorry but this doesn't answer my question. I think you didn't get what I'm trying to ask.
using namespace A; if used outside the main() causes "call of overloaded 'get_value()' is ambiguous" compilation error. Where as it doesn't cause any compilation error when used inside the main().
Here two things are to be considered
using namespace A; // inside or outside main()
using namespace B; // inside...Leave a comment:
-
@weaknessforcat Thanks.
...Code:#include <iostream> #include <cstdlib> namespace A { int a = 10; void get_value(){ std::cout << "a = " << a << std::endl; } } namespace B { int b; void get_value(){ std::cout << "b =" << b << std::endl; } } // using namespace A; if used here generateLeave a comment:
-
Thanks buddy ;) Ok I got it . There is another doubt that I would like to clear.
Do Namespace names (identifier) have global scope with external linkage ?Leave a comment:
-
Confusion regarding C++ namespace .
Please help me clear my doubts, regarding C++ namespaces.
For what I know, Namespace defines a scope. Members defined inside namespace have that namespace scope.
And An object cannot be accessed outside it's scope.
1. If that is true how are we able to access a namespace member outside the namespace ?
2. Do member of namespace have global scope ?
3. If namespace members do not have global...
No activity results to display
Show More
Leave a comment: