XOR-on constants

This is a discussion on XOR-on constants within the C++ Programming forums, part of the General Programming Boards category; inline g_cFloat g_cFloat::m_ffXOr(g_cFloat p_fFloat) { return g_cFloat(m_fFloat ^ p_fFloat); } inline g_cFloat g_cFloat::m_ffXOr(g_cFloat p_fFloat) const { return g_gFloat(m_fFloat ^ p_fFloat); ...

  1. #1
    Unregistered
    Guest

    XOR-on constants

    inline g_cFloat g_cFloat::m_ffXOr(g_cFloat p_fFloat)
    {
    return g_cFloat(m_fFloat ^ p_fFloat);
    }


    inline g_cFloat g_cFloat::m_ffXOr(g_cFloat p_fFloat) const
    {
    return g_gFloat(m_fFloat ^ p_fFloat);
    }

    I was making a modified class for floating point numbers when I suddenly saw there was a need for logic operations such as and, or not and xor, when I got to the xor function. I had made all functions that didn't modify any data in the class constant, but when I tried to perform and xor the constant data it didn't work. why?

    Thanks in advance.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Assuming that m_fFloat is a member variable of your 'g_cFloat' class then:

    m_fFloat ^ p_fFloat will store the result of the operation in the m_fFloat variable; this is maybe causing the problem.

  3. #3
    Unregistered
    Guest
    Probably what so is the case, although I how should I do it then?

    (I've always been under the impression that a=b^c stored a value in a, and a^=b does what you're saying this does)

    and do I do what I wanted to do then?

    ....

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Bitwise operators only work with intergral types.

  5. #5
    Unregistered
    Guest
    thanks.
    Although, I guess I'll have to remove those functions now.

  6. #6
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You could write your own operator^, but without casting/converting to integers you won't be able to use the built in bitwise operator ^.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. COnstants
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 09-01-2007, 04:59 AM
  2. Constants
    By shuo in forum C++ Programming
    Replies: 6
    Last Post: 07-29-2007, 11:51 PM
  3. enum constants as array indices
    By hzmonte in forum C Programming
    Replies: 2
    Last Post: 01-23-2006, 07:23 PM
  4. where are the constants?
    By Raven Arkadon in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2005, 01:07 PM
  5. Help with Constants and enum constants. Newbie learning C++.
    By UnregJDiPerla in forum C++ Programming
    Replies: 5
    Last Post: 01-07-2003, 07:29 PM

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