Skip to main content

Secondary navigation

  • Downloads
  • Integrations
  • Blog
  • Company
    • About Us
    • Team
    • Culture
    • Careers
    • Partners
    • Press
    • Events
  • Contact
    • Contact Us
    • Request Support
    • Subscribe
  • Language
    • English
    • 日本語
    • 简体中文
    • 한국어
    • Deutsche
Home
Perforce

Main Navigation - Mega Menu

  • Products

    Main Navigation - Mega Menu

    • Explore Products
    • All Products

    Main Navigation - Mega Menu

    • Plan
    • Create & Develop
    • Test & Validate
    • Operate, Manage, & Scale
    Helix Core
    Helix4Git
    Helix TeamHub
    Helix ALM
    Hansoft
    Gliffy
    Perfecto
    TestCraft
    Helix QAC
    Klocwork
    Akana
    OpenLogic
    Zend Server
    TotalView
    XRebel
    HostAccess
    SourcePro
    Stingray
    HydraExpress
    PV-WAVE
    Visualization
    IMSL
    Methodics IPLM
    VersIC
    JRebel
  • Solutions

    Main Navigation - Mega Menu

    • Explore Solutions
    • Solutions Overview

    Main Navigation - Mega Menu

    • By Need
    • By Industry

    Main Navigation - Mega Menu

    • Plan
    • Create & Develop
    • Test & Validate
    • Operate, Manage, & Scale

    Main Navigation - Mega Menu

    • Aerospace & Defense
    • Automotive
    • Embedded Systems
    • Semiconductor
    • Energy
    • Financial
    • Game Development
    • Virtual Production
    • Government
    • Medical Devices
      Icon
    • Software

    Main Navigation - Mega Menu

    • Application Lifecycle Management
    • Agile Project Management
    • Diagramming

    Main Navigation - Mega Menu

    • DevOps
    • Version Control
    • IP Lifecycle Management
    • Java Application Development

    Main Navigation - Mega Menu

    • Web & Mobile App Testing
    • Codeless Selenium Automation
    • Static Analysis
    • Audit & Compliance

    Main Navigation - Mega Menu

    • API Management
    • Open Source Support
    • Enterprise PHP
    • HPC Debugging
    • Development Tools & Libraries
  • Customers
  • Resources

    Main Navigation - Mega Menu

    • Explore Resources
    • Papers & Videos
    • Recorded Webinars
    • Events
    • Blog
    • Demos
    • Subscribe
    Image VCS IPreuse Preview new

    How to Make IP Reuse Work For You

    Read Now
  • Support

    Main Navigation - Mega Menu

    • Explore Support
    • Support Plans
    • Self-Service Resources
    • Documentation
    • Video Tutorials
    • Training
    • Consulting
    • Release Notes
    • Download Software
    • Request Support

    Support

    Get answers quick by searching our public knowledgebase

    Visit Perforce KB

  • Try Free
  • Downloads
  • Integrations
  • Blog
  • Company

    Main Navigation - Mega Menu

    • About Us
    • Careers
    • Culture
    • Events
    • Partners
    • Press
    • Team
  • Contact

Version 4.0

High Integrity C++ Coding Standard

Released October 3, 2013

Request PDF Version
High Integrity C++ Coding Standard
0. Introduction
1. General
2. Lexical Conventions
3. Basic Concepts
4. Standard Conversions
5. Expressions
6. Statements
7. Declarations
8. Definitions
9. Classes
10. Derived Classes
11. Member Access Control
12. Special Member Functions
13. Overloading
14. Templates
15. Exception Handling
16. Preprocessing
17. Standard Library
18. Concurrency
19. References
20. Revision History
21. Conditions of Use

10. Derived Classes

10.1 Multiple Base Classes


10.1.1 Ensure that access to base class subobjects does not require explicit disambiguation

A class inherited more than once in a hierarchy, and not inherited virtually in all paths will result in multiple base class subobjects being present in instances of the derived object type. Such objects require that the developer explicitly select which base class to use when accessing members. The result is a hierarchy that is harder to understand and maintain.

class Base
{
public:
void foo ();
};
   
class Derived_left: public Base {};
   
class Derived_right: public Base {};
   
// @@- Non-Compliant: 2 subobjects for 'Base' [email protected]@
class Derived: public Derived_left, public Derived_right
{
};
   
void test()
{
Derived d;
// ambiguous - Derived_left::Base::foo or Derived_right::Base::foo?
d.foo (); 
}

The example above can be made to comply with this rule by using virtual inheritance:

class Base {};
             
class Derived_left: public virtual Base {};
   
class Derived_right: public virtual Base {};
   
class Derived: public Derived_left, public Derived_right // @@+ Compliant [email protected]@
{
};

References

  • HIC++ v3.3 – 3.3.15

View references >

10.2 Virtual Functions


10.2.1 Use the override special identifier when overriding a virtual function

The override special identifier is a directive to the compiler to check that the function is overriding a base class member. This will ensure that a change in the signature of the virtual function will generate a compiler error.

#include <cstdint>
   
class A {
public:
virtual void f(int64_t);
};
          
class B : public A {
public:
void f(int32_t) override;   // @@+ Compliant: Compile Error [email protected]@
};

Note: The following was considered good C++03 style:

#include <cstdint>
   
class A {
public:
virtual void f(int32_t);
};
          
class B : public A {
public:
virtual void f(int32_t);   // @@- Non-Compliant [email protected]@
};
   
void f(A & a)
{
a.f(0);                // Results in (*@\color{blue}{B::f}@*) being called
}

However, this provided no guarantees and no additional checking by the compiler if the function signature was changed.

#include <cstdint>
   
class A {
public:
virtual void f(int64_t);
};
          
class B : public A {
public:
virtual void f(int32_t);   // @@- Non-Compliant [email protected]@
};
   
void f(A & a)
{
a.f(0);                // Results in (*@\color{red}{A::f}@*) being called!!!!
}

References

  • HIC++ v3.3 – 3.3.16

View references >

10.3 Abstract Classes


10.3.1 Ensure that a derived class has at most one base class which is not an interface class

An interface class has the following properties:

  • All public functions are pure virtual functions or getters.
  • There are no public or protected data members.
  • It contains at most one private data member of integral or enumerated type.

Inheriting from two or more base classes that are not interfaces, is rarely correct. It also exposes the derived class to multiple implementations, with the risk that subsequent changes to any of the base classes may invalidate the derived class. On the other hand, it is reasonable that a concrete class may implement more than one interface.

#include <cstdint>
   
class A
{
public:
virtual ~A () = 0;
virtual void foo () = 0;
};
   
class B
{
public:
virtual ~B () = 0;
virtual void bar () = 0;
};
   
class C
{
public:
C ();
void foo ();
virtual ~C ();
   
private:
int32_t m_i;
};
   
// @@+ Compliant [email protected]@
class D: public A, public B, public C
{
public:
~ D();
};
               
class E
{
public:
E ();
};
               
// @@- Non-Compliant [email protected]@
class F : public E, public D
{
};

References

  • JSF AV C++ Rev C – 87
  • JSF AV C++ Rev C – 88
  • HIC++ v3.3 – 3.4.6

View references >

Request PDF Version

 

 

Book traversal links for 10. Derived Classes

  • ‹ 9. Classes
  • High Integrity C++ Coding Standard
  • 11. Member Access Control ›

Footer menu

  • Products
    • Version Control System
    • Helix Core
    • Methodics IPLM
    • VersIC
    • Enterprise Agile Planning
    • Hansoft
    • Dev Collaboration
    • Helix TeamHub
    • Helix Swarm
    • Helix4Git
    • Development Lifecycle Management
    • Helix ALM
    • Surround SCM
    • Static Analysis
    • Helix QAC
    • Klocwork
    • Development Tools & Libraries
    • HostAccess
    • HydraExpress
    • PV-WAVE
    • SourcePro
    • Stingray
    • Visualization
  • Solutions
    • By need
    • Version Control
    • Application Lifecycle Management
    • Agile Project Management
    • Backlog Management
    • Project Portfolio Management
    • Audit & Compliance
    • DevOps
    • Static Analysis
    • IP Lifecycle Management
    • By industry
    • Game Development
    • Life Sciences
    • Software
    • Automotive
    • Embedded Systems
    • Government
    • Finance
    • Energy & Utilities
    • Aerospace & Defense
    • Virtual Production
    • Semiconductor
  • Resources
    • Papers & Videos
    • Events & Webinars
    • Recorded Webinars
    • Blog
  • Support
    • Documentation
    • Request Support
    • Video Tutorials
    • Training
    • Consulting
    • Release Notes
    • Download
  • Customers
    • Case Studies
  • About
    • Our Team
    • Our Culture
    • Careers
    • Press
    • Contact
  • Partners
    • Integrations
    • Resellers
  • Quick links
    • Try For Free
    • Helix Core Demo
    • Helix ALM Demo
    • Subscription Center
    • Customer Support Login
    • Licensing Requests
    • Educational Licenses
    • How to Buy
Home
Perforce

Copyright © 2021 Perforce Software, Inc. All rights reserved.  |  Sitemap  |  Terms of Use  |  Privacy Policy

Social menu

  • Facebook
  • Twitter
  • Google+
  • LinkedIn
  • YouTube
  • RSS