Thread: Assign. question, please explain

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    9

    Assign. question, please explain

    I have the follow question

    http://img41.imageshack.us/img41/5318/94404328.jpg

    can anyone explain the answer to me.
    I'm not sure what is correct.

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    The purpose of these board is not for other people to do your homework for you. Try things out work on your own, homework has a purpose. If you still have trouble with a specific piece of code or concept please feel free to ask. But please do not ask people to do your entire homework for you, it simply annoys people most of the time.
    You have a C++ compiler, do you not? Ask it your question. And/or research the web - the answer is also contained in this site's Tutorial's section.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    9
    Hey, this has nothing to do with my homework. I have an exam tomorrow and these question are from a exam-set from a earlier year. The solutions are not explained, thus my question here. And as you can see im NOT asking for the solution, i am asking for an explaination. If you have a problem with that, dont read my post.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    9
    And NO i don't have a c++ compiler. I can't install anything on this machine. However, i am also more interested in the explanation.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by lesodk
    The solutions are not explained, thus my question here. And as you can see im NOT asking for the solution, i am asking for an explaination.
    Okay, so give the solution and your best shot at an explanation. Maybe your explanation is correct.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    9
    Okay. I would think that only the first one is correct, since a pointer to a base class can be assigned to a pointer to a derived class. The subsequent questions are illegal because the field "speed" is protected. However the correct answer is, that only the third assignment is illegal. That is what confuses me.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by lesodk
    I would think that only the first one is correct, since a pointer to a base class can be assigned to a pointer to a derived class. The subsequent questions are illegal because the field "speed" is protected. However the correct answer is, that only the third assignment is illegal.
    In my opinion, you are correct, both in solution and reasoning. The "model answer" is wrong. We also have to assume that Boat and Car inherit via virtual inheritance from Transport so as to avoid the diamond inheritance problem.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. One Easy" C " Question. Please Solve and Explain.
    By RahulDhanpat in forum C Programming
    Replies: 18
    Last Post: 03-24-2008, 01:39 PM
  2. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  3. Question i dont understand
    By muran_pling in forum C++ Programming
    Replies: 4
    Last Post: 06-03-2007, 06:22 AM
  4. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  5. question once again..
    By sunnycyboid in forum C Programming
    Replies: 1
    Last Post: 11-08-2002, 04:57 AM