Thread: c++ code urgent help needed

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    222

    c++ code urgent help needed

    What is the output of the following code?
    Code:
    Base Base {
    public:
             void fn (int x) {cout << "Base",}
    };
    
    class derived : public Base {
    public :
             void fn (double *pd) {cout << "Derived"};
    };
    
    int main() {
    Derived d;
    d.fun (10);
    }
    a) base
    b) derived
    c) Compiler error; invalid convert int to double missing derived ::fun(int);
    d) linker error

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Before I offer any assistance, it's important to note that the "urgency" of your problem is no concern of the users of this forum. if this is a school assignment, and you waited til the last minute to do it, that's your problem, not ours.

    the answer is none of the above. none of the four answers provided is correct.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    please assume necessary header files here. I am eager to know the answer here. if I am wrong , correct me with proper logic here. I think answer c)..what do you think none of them are correct?

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by leo2008 View Post
    please assume necessary header files here. I am eager to know the answer here. if I am wrong , correct me with proper logic here. I think answer c)..what do you think none of them are correct?
    Likely because they knows or they compiled/ran the code.

    I see an error in it and I am a C programmer just learning C++.

    You really need to try these things in a compiler or learn to cut and paste.
    Because it has a obvious typo type of mistake(s) in what you posted.

    Edit: I just compiled it and I confirmed I was right about the mistake.

    Tim S.
    Last edited by stahta01; 03-12-2013 at 10:48 AM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    did you get compiler error or linker error? which answer do you think is correct here out of 4 choices i gave you?

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    did you get compiler error or linker error?
    The question is did you get a compiler or linker error. This is your assignment, you tell what you tried and the results you got. Then ask questions based on this information.

    Jim

  7. #7
    Registered User
    Join Date
    Nov 2008
    Posts
    222

    Thumbs up

    Quote Originally Posted by jimblumberg View Post
    The question is did you get a compiler or linker error. This is your assignment, you tell what you tried and the results you got. Then ask questions based on this information.

    Jim
    i am linux guy whos learnign windows...if you claim that you are an expert, provide your answer instead of giving bull ........ crap!!

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    What difference does the operating system make for this question?

    I will not provide you an answer, you need to compile and run the code and then maybe you can answer your own question. If you don't understand the results you get then you can ask specific questions based upon the results you received. I am not giving you bull crap, just trying to tell you to do your own experiments, then you should be able to answer this question quite easily.


    Jim

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by leo2008 View Post
    i am linux guy whos learnign windows...if you claim that you are an expert, provide your answer instead of giving bull ........ crap!!
    We are not hired to answer your questions, nor are we required to do that. We are doing this in our free time because we find it entertaining to do so.
    If you are going to be mean to us, we have no obligation to answer you. We are doing this as much for ourselves as for making sure newbies, such as yourself, learn as much as possible.
    If you don't like that, then that's fine. You don't have to ask us. You can take your question elsewhere.
    But if you DO want an answer from here, then you really should follow jim's advice. For your sake, as much as ours. You learn much more by doing that.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by leo2008 View Post
    i am linux guy whos learnign windows...
    no. what you are is an immature freeloader with no work ethic. you will learn absolutely nothing if we give you the answers. if you intend to go through all of your education this way, then it should be our duty to ensure your outright failure. as a lazy programmer with a degree, you will be far more dangerous than a hard working programmer with no formal training. if you insist upon demanding answers without putting in any effort at all, I will give you nothing but wrong answers in the hope that you fail your assignments and exams. you have been warned.

  11. #11
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    The output of your program is "go away"
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  12. #12
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    if you insist upon demanding answers without putting in any effort at all, I will give you nothing but wrong answers in the hope that you fail your assignments and exams.
    Well, he might do that, but I promise that I will only ever give you correct answer.

    The answer is "D"; linking will fail because you haven't implemented the function `void fn (int x)' in `derived'.

    Soma

  13. #13
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    while running with online compiler, i got below error.


    Line 1: error: 'Base' does not name a type
    compilation terminated due to -Wfatal-errors.

  14. #14
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    So it looks like you have an error. Do you think this is a compile or link error?

    Jim

  15. #15
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    it looks to me like linker error? what do you think?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. win32 code help needed, please its urgent
    By leo2008 in forum Windows Programming
    Replies: 3
    Last Post: 03-12-2013, 08:12 PM
  2. urgent help needed win32 c++ code , please help me!!!!
    By leo2008 in forum Windows Programming
    Replies: 1
    Last Post: 03-12-2013, 10:22 AM
  3. Urgent.Help needed
    By adgav in forum C Programming
    Replies: 10
    Last Post: 03-13-2006, 06:20 AM
  4. urgent help needed
    By Leeman_s in forum Windows Programming
    Replies: 1
    Last Post: 11-11-2002, 04:27 PM
  5. Urgent help needed!!!
    By gibs21 in forum C Programming
    Replies: 2
    Last Post: 09-26-2002, 01:45 PM