inner class method definition outside of a template class

x86-Debug

I have class Array that defines inner class const_iterator

template <class T, int SIZE = 100>
class Array
{
    // my class here
public:
    class const_iterator
    {
     // my class here
    };


    void insert(const_iterator position, int value);
};


template <class T, int SIZE /*= 100*/>
void Array<T, SIZE>::insert(const_iterator position, int value)
{
    // impl
}

Is it normal, that outside of the class I have defined the function and have used const_iterator position as the first argument type instead of writing typename Array<T, SIZE>::const_iterator position? Is this standard compliant? What if there is another const_iterator class outside of class Array?

Barry

Yes, it's perfectly fine and standard (well, within the class you need to declare const_iterator first before having your insert() member function take a parameter of that type).

For member function definitions outside of the class, every name that comes after the class name scope introducer is looked up within the scope of that class first. So if there were another const_iterator outside of Array, we would still find the inner one first since that's the scope we start looking in. Note that it's only those names after the class introducer that have this special lookup:

// this is okay
template <class T, int SIZE>
typename Array<T, SIZE>::const_iterator Array<T, SIZE>::some_method() { ... }

// error: this does *not* find the nested const_iterator class
template <class T, int SIZE>
const_iterator Array<T, SIZE>::some_method() { ... }

// this is okay. trailing return type comes after the class introducer
template <class T, int SIZE>
auto Array<T, SIZE>::some_method() 
    -> const_iterator
{ ... }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Move method definition for template nested class outside declaration

From Dev

Partial Template specialization definition outside of class definition

From Dev

Partial Template specialization definition outside of class definition

From Dev

TypeScript - How to add a method outside the class definition

From Dev

Reference instance method outside class definition

From Dev

TypeScript - How to add a method outside the class definition

From Dev

Out-of-class definition of function of specialized inner class template?

From Dev

Define operator[]() (array subscription) for template class outside of class definition

From Dev

Nested class definition outside outer class's, while outer class contains instance of inner class

From Dev

Python - declare method name in dictionary with method definition in outside class

From Dev

Python - declare method name in dictionary with method definition in outside class

From Dev

In template class member function body outside class definition, when are template parameters required?

From Dev

specialize template with inner class template of a class template

From Dev

friend not allowed outside of a class definition

From Dev

Variable assignment outside class definition

From Dev

Move function outside class definition

From Dev

declaration of templated function (over container type) inside class and definition of it outside a template class over container type-

From Dev

Dynamic method definition in a class

From Dev

regarding a method definition in a class

From Dev

Mocking a method outside of a class

From Dev

Declare method outside of class

From Dev

How do I define a template member function outside of a full specialized template class's definition?

From Dev

How do I define a template member function outside of a full specialized template class's definition?

From Dev

Method local inner class vs inner class

From Dev

What kind of class template definition is this?

From Dev

Template argument not deduced for inner class

From Dev

Using class member variables that hold functions in definition of inner structures that will be used as template arguments of an unordered_map object

From Dev

use inner class in a template class where it belong to

From Dev

static_assert inside/outside class definition

Related Related

  1. 1

    Move method definition for template nested class outside declaration

  2. 2

    Partial Template specialization definition outside of class definition

  3. 3

    Partial Template specialization definition outside of class definition

  4. 4

    TypeScript - How to add a method outside the class definition

  5. 5

    Reference instance method outside class definition

  6. 6

    TypeScript - How to add a method outside the class definition

  7. 7

    Out-of-class definition of function of specialized inner class template?

  8. 8

    Define operator[]() (array subscription) for template class outside of class definition

  9. 9

    Nested class definition outside outer class's, while outer class contains instance of inner class

  10. 10

    Python - declare method name in dictionary with method definition in outside class

  11. 11

    Python - declare method name in dictionary with method definition in outside class

  12. 12

    In template class member function body outside class definition, when are template parameters required?

  13. 13

    specialize template with inner class template of a class template

  14. 14

    friend not allowed outside of a class definition

  15. 15

    Variable assignment outside class definition

  16. 16

    Move function outside class definition

  17. 17

    declaration of templated function (over container type) inside class and definition of it outside a template class over container type-

  18. 18

    Dynamic method definition in a class

  19. 19

    regarding a method definition in a class

  20. 20

    Mocking a method outside of a class

  21. 21

    Declare method outside of class

  22. 22

    How do I define a template member function outside of a full specialized template class's definition?

  23. 23

    How do I define a template member function outside of a full specialized template class's definition?

  24. 24

    Method local inner class vs inner class

  25. 25

    What kind of class template definition is this?

  26. 26

    Template argument not deduced for inner class

  27. 27

    Using class member variables that hold functions in definition of inner structures that will be used as template arguments of an unordered_map object

  28. 28

    use inner class in a template class where it belong to

  29. 29

    static_assert inside/outside class definition

HotTag

Archive