Skip to main content

Secondary navigation

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

Main Navigation - Mega Menu

  • Products

    Main Navigation - Mega Menu

    • Explore Products
    • All Products
    Helix Core
    Version Control
    Helix TeamHub
    Code Hosting for Git, SVN, Hg
    Methodics IPLM
    IP Lifecycle Management
    Gliffy
    Diagramming
    JRebel
    Java Application Development
    Helix DAM
    Digital Asset Management
    Helix Core
    Version Control
    Helix TeamHub
    Code Hosting for Git, SVN, Hg
    Methodics IPLM
    IP Lifecycle Management
    Gliffy
    Diagramming
    JRebel
    Java Application Development
    Helix DAM
    Digital Asset Management
  • Solutions

    Main Navigation - Mega Menu

    • Explore Solutions
    • Solutions Overview

    Main Navigation - Mega Menu

    • By Need
    • By Industry

    Main Navigation - Mega Menu

    • Application Lifecycle Management
    • Agile Project Management
    • Diagramming
    • DevOps
    • Version Control
    • IP Lifecycle Management
    • Java Application Development
    • Web & Mobile App Testing
    • Codeless Selenium Automation
    • Static Analysis & SAST
    • Audit & Compliance
    • API Management
    • Open Source Support
    • Enterprise PHP
    • HPC Debugging
    • Development Tools & Libraries

    Main Navigation - Mega Menu

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

    Main Navigation - Mega Menu

    Main Navigation - Mega Menu

    Main Navigation - Mega Menu

    Main Navigation - Mega Menu

  • Customers
  • Resources

    Main Navigation - Mega Menu

    • Explore Resources
    • Papers & Videos
    • Recorded Webinars
    • Events & Webinars
    • Blog
    • Free Trials
    • Subscribe
    Version Control in Virtual Production

    Version Control in Virtual Production Field Guide

    Read Now
  • Support
  • Services

    Main Navigation - Mega Menu

    • Consulting/Professional Services
    • Training

    Main Navigation - Mega Menu

    • Consulting Services Overview
    • Akana
    • BlazeMeter
    • Helix ALM
    • Helix Core
    • Helix QAC
    • Klocwork
    • Methodics IPLM
    • OpenLogic
    • Perfecto
    • Zend

    Main Navigation - Mega Menu

    • Training Overview
    • Hansoft
    • Helix ALM
    • Helix Core
    • Helix QAC
    • Klocwork
    • OpenLogic
    • Perfecto
    • Zend
  • 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
    • Plan
    • Helix ALM
    • Hansoft
    • Create & Develop
    • Helix Core
    • Helix4Git
    • Helix DAM
    • Helix TeamHub
    • Helix Swarm
    • Methodics IPLM
    • VersIC
    • Test & Validate
    • Helix QAC
    • Klocwork
    • Operate, Manage, & Scale
    • SourcePro
    • HostAccess
    • HydraExpress
    • PV-WAVE
    • Stingray
    • Visualization
  • Solutions
    • By need
    • Application Lifecycle Management
    • Agile Project Management
    • DevOps
    • Version Control
    • IP Lifecycle Management
    • Static Analysis
    • Audit & Compliance
    • Backlog Management
    • Project Portfolio Management
    • By industry
    • Aerospace & Defense
    • Automotive
    • Embedded Systems
    • Semiconductor
    • Energy & Utilities
    • Finance
    • Game Development
    • Virtual Production
    • Government
    • Life Sciences
    • Software
  • Services
    • Consulting/Professional Services
    • Consulting Services Overview
    • Akana
    • BlazeMeter
    • Helix ALM
    • Helix Core
    • Helix QAC
    • Klocwork
    • Methodics IPLM
    • OpenLogic
    • Perfecto
    • Zend
    • Training
    • Training Overview
    • Hansoft
    • Helix ALM
    • Helix Core
    • Helix QAC
    • Klocwork
    • OpenLogic
    • Perfecto
    • Zend
  • Resources
    • Papers & Videos
    • Events & Webinars
    • Recorded Webinars
    • Blog
    • Perforce U
  • Support
  • Customers
    • Case Studies
  • About
    • Our Team
    • Our Culture
    • Careers
    • Press
    • Contact Us
  • Partners
    • Integrations
    • Resellers
  • Quick links
    • Free Trials
    • Subscription Center
    • Customer Support Login
    • Educational Licenses
    • How to Buy
Home
Perforce

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

Social menu

  • Facebook
  • Twitter
  • LinkedIn
  • YouTube
  • RSS
Send Feedback