Results 1 to 4 of 4

Thread: Some Theoretical Questions

  1. #1

    Thread Starter
    Hyperactive Member anita2002's Avatar
    Join Date
    Dec 2001
    Location
    In u'r Heart
    Posts
    482

    Thumbs up Some Theoretical Questions

    Hi friends,
    I'm not that much famililar with c++ But my friend has some
    the theoretical doubts. So I'm asking them here.

    1)Whether it is necessary to have a name for c++ object?
    2)Can a member function delete THIS pointer? Explain.
    3)Explain arry based I/O in c++
    4)why in c++ Union can't have the static data members?
    5)Where the member functions of c++ class stored?
    6)what is the difference between mutable and immutable values?
    7)Why it is not possible to get addresses of constructor and destructor member functions?
    8)Why it is not possible to get addresses of conversation function?
    9)Can a recursive c++ function have default argument? Justify.
    10)Can a exception handler have default arguments? justify.
    11)Give the relationshis among c++ classes.
    12)Discuss in brief the functionality of the built in function
    "istrem putback(char)"
    13)Can we use the same function name for a member function and a non member function in the same program file? justify u'r answer.
    14)What is the difference between a non constant object and a constant object?

    Please answer me if u know any of these questions.
    Thanks in advance.
    Anita
    Can't imagine life without VB
    (Various Boyfriends)

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    1)Whether it is necessary to have a name for c++ object?
    Do you mean an object-type or an object-instance? A type doesn't have to have a name:
    Code:
    struct
    {
        int x;
    } my_instance;
    2)Can a member function delete THIS pointer? Explain.
    Yes, it can, but it should not do that. There is no guarantee that the this pointer can be deleted (e.g. is allocated as a single object)

    3)Explain arr[a]y based I/O in c++
    What do you mean by array based I/O?

    4)why in c++ Union can't have the static data members?
    In a union only one member can be used at one time. If it has static members, you could use all of those static members at the same time.

    5)Where the member functions of c++ class stored?
    Member functions are stored just like all other functions, inside the program file (and the memory the OS loads it into)
    If a class has virtual members, the adresses are usually stored in a table, and each instance of the class stores a pointer to that table. (note: this is implementation specific, and you have nothing to do with this)

    6)what is the difference between mutable and immutable values?
    A mutable member of a class can be changed by a member function, even if the this pointer passed to that function is const:
    Code:
    struct x
    {
        int a;
        mutable int b;
        void test() const
        {
             a = 1; // error
             b = 1; // okay
        }
    };
    7)Why it is not possible to get addresses of constructor and destructor member functions?
    Constructors and destructors are not really considered functions. Also, calling them via a function pointer would be meaningless.

    8)Why it is not possible to get addresses of conversation function?
    See 7.

    9)Can a recursive c++ function have default argument? Justify.
    Yes, a recursive function is in no way different from a normal function.

    10)Can a exception handler have default arguments? justify.
    You mean 'catch (something)'? No, catch is not a function, and it can't have default arguments. A catch always catches exactly one thing (the exception)

    11)Give the relationshis among c++ classes.
    What do you mean?

    12)Discuss in brief the functionality of the built in function
    "istre[a]m putback(char)"

    13)Can we use the same function name for a member function and a non member function in the same program file? justify u'r answer.
    Yes. Members of a class are difined inside another 'namespace'. You can use the same name as often as you want in different scopes

    14)What is the difference between a non constant object and a constant object?
    A const object cannot be modified, a const object can.

  3. #3
    Addicted Member dolor's Avatar
    Join Date
    Sep 2002
    Location
    in a place seldom found on a map
    Posts
    220

    i have a theory

    Absolutely anything is possible...theoretically. You see, theoretically, you could fall to the sky. It's all relative. Sorry, had to get that off my chest.
    - you've been privileged to read a post by Miz

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Seems very much like some test to me...

    I'll answer them anyway... (those not already answered)

    2)Can a member function delete THIS pointer? Explain.
    It can. MFC does it. But as twanvl said you should really know what you're doing. The object could for example be allocated on the stack, in which case it should NOT delete itself. The problem is that an object can't find out if it is allocated on the stack or not.

    4)why in c++ Union can't have the static data members?

    Unions come from C where there are no static members. It wouldn't make sense extending them to allow this.

    12)Discuss in brief the functionality of the built in function
    "istre[a]m putback(char)"

    putback pushes a byte already read from the stream back into it, so that the next byte read is this character. This makes sense if you read from the stream in a loop and break the loop when you recieve a special byte, but you still want this byte to remain in the stream. In this case you can extract it and then push it back after the loop.

    14)What is the difference between a non constant object and a constant object?
    A const object cannot be modified, a [non-]const object can.

    But as I said, those are surely not question "your friend likes to know", those are questions from some kind of test.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width