Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #12497

would you consider this function const?

From john <gh14tq5@yahoo.com>
Newsgroups comp.lang.c++
Subject would you consider this function const?
Date 2011-12-14 10:17 -0500
Organization Aioe.org NNTP Server
Message-ID <jcaem0$gac$1@speranza.aioe.org> (permalink)

Show all headers | View raw


Are the following functions an abuse of good usage of 'const'?  I think 
func3 is an abuse, but I'm not sure if func1 or func2, in isolation, 
would be considered poor usage since they do not actually modify an 
instance of A themselves (although they do leave the door open).  Thanks.

class B;

class A
{

    B* m_b;

    public:

    void func1(A* &a) const
    {
       a = const_cast<A*>(this);
    }

    B* func2() const { return m_b; }

    // because we could do
    void func3() const
    {
       // now we can change m_b;
       B* b = func2();

       // now we can change this;
       A* a;
       func1(a);
    }

};

Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

would you consider this function const? john <gh14tq5@yahoo.com> - 2011-12-14 10:17 -0500
  Re: would you consider this function const? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-12-14 11:19 -0500
    Re: would you consider this function const? john <gh14tq5@yahoo.com> - 2011-12-15 08:10 -0500
      Re: would you consider this function const? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-12-15 08:21 -0500
        Re: would you consider this function const? john <gh14tq5@yahoo.com> - 2011-12-15 08:44 -0500
          Re: would you consider this function const? Leigh Johnston <leigh@i42.co.uk> - 2011-12-15 14:07 +0000
            Re: would you consider this function const? Leigh Johnston <leigh@i42.co.uk> - 2011-12-15 14:14 +0000
          Re: would you consider this function const? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-12-15 09:11 -0500
            Re: would you consider this function const? john <gh14tq5@yahoo.com> - 2011-12-15 09:30 -0500
              Re: would you consider this function const? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-12-15 10:06 -0500
                Re: would you consider this function const? john <gh14tq5@yahoo.com> - 2011-12-15 12:42 -0500
                Re: would you consider this function const? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-12-15 13:32 -0500
    Re: would you consider this function const? yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-12-19 18:16 +0000
      Re: would you consider this function const? Tobias Müller <troplin@bluewin.ch> - 2011-12-19 19:05 +0000
        Re: would you consider this function const? Joshua Maurice <joshuamaurice@gmail.com> - 2011-12-19 14:36 -0800
          Re: would you consider this function const? Tobias Müller <troplin@bluewin.ch> - 2011-12-20 06:28 +0000
            Re: would you consider this function const? Joshua Maurice <joshuamaurice@gmail.com> - 2011-12-19 23:48 -0800

csiph-web