MC++/portability

This is a discussion on MC++/portability within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Elysia Hoo-my. Doesn't look like it likes that, huh? You're going to have to remove the const ...

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    Hoo-my. Doesn't look like it likes that, huh? You're going to have to remove the const from setNext to make it work.
    Haha... didn't think of that. Of course, if it assigns the variable to the class member function which isn't const, of course the set function can't take a const pointer since the class can modify it later.
    Yes, that's my thoughts too - and I made the same mistake. I just want to have the line of the error clarified.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Registered User
    Join Date
    Jan 2008
    Posts
    24
    Quote Originally Posted by matsp View Post
    And which line do you get that error on? Where you are calling setNext() or the line where you define the function setNext()?

    --
    Mats
    It was on the definition line.

    So would this be one of the cases where you'd want to return a const pointer instead of a pointer to a const object?

    Edit: Errr... I meant 'accept', not 'return'.
    Last edited by drrcknlsn; 01-25-2008 at 05:15 PM.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,014
    No, the setNext musn't take a pointer to const (const T*), because you can't demote to non-const w/o a cast (a bad cast).
    You can take a const pointer (T* const), sure, but it doesn't really help.
    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.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looking for sample MC test questions for a job
    By garp in forum C Programming
    Replies: 2
    Last Post: 09-29-2003, 06:30 AM
  2. MC Hammer
    By Zewu in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 07-06-2003, 06:17 PM
  3. Recursion = headache;
    By RoD in forum C++ Programming
    Replies: 9
    Last Post: 12-20-2002, 09:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21