JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Studio 12.3: C++ User's Guide     Oracle Solaris Studio 12.3 Information Library
search filter icon
search icon

Document Information

Preface

Part I C++ Compiler

1.  The C++ Compiler

2.  Using the C++ Compiler

3.  Using the C++ Compiler Options

Part II Writing C++ Programs

4.  Language Extensions

5.  Program Organization

6.  Creating and Using Templates

7.  Compiling Templates

7.1 Verbose Compilation

7.2 Repository Administration

7.2.1 Generated Instances

7.2.2 Whole-Class Instantiation

7.2.3 Compile-Time Instantiation

7.2.4 Template Instance Placement and Linkage

7.3 External Instances

7.3.1 Possible Cache Conflicts

7.3.2 Static Instances

7.3.3 Global Instances

7.3.4 Explicit Instances

7.3.5 Semi-Explicit Instances

7.4 Template Repository

7.4.1 Repository Structure

7.4.2 Writing to the Template Repository

7.4.3 Reading From Multiple Template Repositories

7.4.4 Sharing Template Repositories

7.4.5 Template Instance Automatic Consistency With -instances=extern

7.5 Template Definition Searching

7.5.1 Source File Location Conventions

7.5.2 Definitions Search Path

7.5.3 Troubleshooting a Problematic Search

8.  Exception Handling

9.  Improving Program Performance

10.  Building Multithreaded Programs

Part III Libraries

11.  Using Libraries

12.  Using the C++ Standard Library

13.  Using the Classic iostream Library

14.  Building Libraries

Part IV Appendixes

A.  C++ Compiler Options

B.  Pragmas

Glossary

Index

7.5 Template Definition Searching

When you use the definitions-separate template organization, template definitions are not available in the current compilation unit, and the compiler must search for the definition. This section describes how the compiler locates the definition.

Definition searching is somewhat complex and prone to error. Therefore, you should use the definitions-included template file organization if possible. Doing so helps you avoid definition searching altogether. See 5.2.1 Template Definitions Included.


Note - If you use the -template=no%extdef option, the compiler will not search for separate source files.


7.5.1 Source File Location Conventions

Without the specific directions provided with an options file, the compiler uses a Cfront-style method to locate template definition files. This method requires that the template definition file contain the same base name as the template declaration file. This method also requires the template definition file to be on the current include path. For example, if the template function foo() is located in foo.h, the matching template definition file should be named foo.cc or some other recognizable source-file extension (.C, .c, .cc, .cpp, .cxx, or .c++). The template definition file must be located in one of the normal include directories or in the same directory as its matching header file.

7.5.2 Definitions Search Path

As an alternative to the normal search path set with –I, you can specify a search directory for template definition files with the option –ptidirectory. Multiple -pti flags define multiple search directories, that is, a search path. If you use -ptidirectory, the compiler looks for template definition files on this path and ignores the –I flag. Because the -ptidirectory flag complicates the search rules for source files, use the -I option instead of the -ptidirectory option.

7.5.3 Troubleshooting a Problematic Search

Sometimes the compiler generates confusing warnings or error messages because it is looking for a file that you don’t intend to compile. Usually, the problem is that a file, for example foo.h, contains template declarations and another file, such as foo.cc, gets implicitly included.

If a header file, foo.h, has template declarations, the compiler searches for a file called foo with a C++ file extension (.C, .c, .cc, .cpp, .cxx, or .c++) by default. If the compiler finds such a file, it includes the file automatically. See 7.5 Template Definition Searching for more information on such searches.

If you have a file foo.cc that you don’t intend to be treated this way, you have two options: