User Profile

Collapse

Profile Sidebar

Collapse
carbon
carbon
Last Activity: Jan 1 '15, 04:33 PM
Joined: Mar 12 '14
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • C++ What is the use of a implict default constructor provided by the comiler ?

    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 ?
    See more | Go to post

  • 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.
    See more | Go to post

    Leave a comment:


  • carbon
    replied to Need help c++ reference.
    in C
    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.

    Code:
    char* const &r = a;
    The above code works because here, r has been declared a reference to a constant pointer that is pointing to a character type.


    Code:
    const char*  &r = a;
    The above code doesn't work as here, r...
    See more | Go to post

    Leave a comment:


  • carbon
    started a topic Need help c++ reference.
    in C

    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;
    }
    See more | Go to post

  • carbon
    replied to Confusion regarding C++ namespace .
    in C
    "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...
    See more | Go to post

    Leave a comment:


  • carbon
    replied to Confusion regarding C++ namespace .
    in C
    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...
    See more | Go to post

    Leave a comment:


  • carbon
    replied to Confusion regarding C++ namespace .
    in C
    @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 generate
    ...
    See more | Go to post

    Leave a comment:


  • carbon
    replied to Confusion regarding C++ namespace .
    in C
    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 ?
    See more | Go to post

    Leave a comment:


  • carbon
    started a topic Confusion regarding C++ namespace .
    in C

    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...
    See more | Go to post
No activity results to display
Show More
Working...