Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There can be several linker issues when using pointers to a Class within another Class in C++ where an undefined reference occurs. These issues may include:

  1. Missing implementation of the base class: If the base class, i.e., the class to which the pointer is pointing to, is missing the implementation of one or more of its member functions or variables, then the linker may fail to find the reference to that member, resulting in an undefined reference error.

  2. Incorrect or incomplete linkage: When using pointers, it is crucial to ensure that all the source files and their dependencies are compiled and linked correctly. If any of the files are not linked or improperly linked, then the linker may fail to find the reference to the member, causing the error.

  3. Circular dependency: If there is a circular dependency between the classes, i.e., each class refers to the other, then the linker may not be able to resolve the dependency, leading to an undefined reference error.

  4. Use of templates: When using templates, it is essential to remember that the definition of the member functions must be included in the header file. If the definition is not included, the linker may fail to find the reference, resulting in an undefined reference error.

  5. Incorrect use of namespaces: If the classes are declared or defined in different namespaces, it may lead to linker errors as the linker may not be able to find the reference between the classes in different namespaces.

In conclusion, linker issues can occur when using pointers to a Class within another Class in C++. They may be due to missing implementation, incorrect linkage, circular dependency, using templates, or incorrect use of namespaces.