Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Google C++ Style Guide

📅 2014-Aug-13 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ cpp ⬩ 📚 Archive

One of the popular guides to naming and structuring C++ code is the Google C++ Style Guide.

Here is code demonstrating the usage of this style guide:

// Code demonstrating the Google C++ Style Guide:
// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml

// Global variable
int g_widget_num = 0;

// Constant
const int kCameraMax = 890;

// Type
typedef std::vector<int> IntVec;

// Enumeration
enum ImageType
{
    kColor,
    kMono,
    kDepth,
};

// Class
class YukoCamera
{
    public:

    // Class-internal types
    struct Sensor
    {
        int ccd_length_;
        int ccd_width_;
    };

    // C-Dtors
    YukoCamera();
    ~YukoCamera();

    // Methods
    void InitCamera();
    void CaptureColorPhoto();
    void StopCamera();

    // Accessor methods
    int get_cam_width() const;
    int get_cam_height() const;

    private:

    void StartSensor();
    void StopSensor();

    int cam_width_;
    int cam_height_;
    Sensor sensor_;
};

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧