Thread: Using same code to do bit-checking across multiple classes' private variables

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    27

    Using same code to do bit-checking across multiple classes' private variables

    Hi all,

    I am writing a bit-check function just to make it easier on myself to check status flags in my classes. I use char variables and each bit represents something on or off. Since I have numerous classes that will use this functionality, it makes sense to write and compile the code only one time rather than for each class. I was thinking of writing the function and including it as a "friend" function to each class that needs it. Is that an appropriate way to do it?

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Why not just make it a "normal" function and have a function that returns the "flag" that can be used by this function?

    Jim

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by DarkMasterBosel View Post
    Hi all,

    I am writing a bit-check function just to make it easier on myself to check status flags in my classes. I use char variables and each bit represents something on or off. Since I have numerous classes that will use this functionality, it makes sense to write and compile the code only one time rather than for each class. I was thinking of writing the function and including it as a "friend" function to each class that needs it. Is that an appropriate way to do it?
    Remember, the primary purpose of friend functions is to allow external function access to private/protected data and methods of a class.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes and private:
    By jocdrew21 in forum C++ Programming
    Replies: 10
    Last Post: 10-01-2013, 12:34 PM
  2. private variables
    By cable in forum C++ Programming
    Replies: 1
    Last Post: 12-13-2011, 12:16 PM
  3. Nested Class Accessing Classes Private Variables
    By SterlingM in forum C++ Programming
    Replies: 1
    Last Post: 03-07-2011, 01:06 AM
  4. about private class variables
    By bulletbutter in forum C++ Programming
    Replies: 5
    Last Post: 04-18-2008, 12:13 PM
  5. Public vs. Private variables in classes
    By blankstare77 in forum C++ Programming
    Replies: 13
    Last Post: 08-31-2005, 05:43 PM