Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C++ Inline Question

Name: Anonymous 2012-01-19 20:40

Suppose the following:

struct C {
    void method() {}
};


template<typename T>
struct D {
    void method1() {}
    void method2();
};

template<typename T> void D<T>::method2() {}

Since C::method() is defined inside the class, it is defined as though as it were declared inline. Does the same apply to templates?

That is:
- Is D<T>::method1() inline?
- Is D<T>::method2() inline?

Thank you, /prog/riders.

Name: Anonymous 2012-01-19 20:45

Also, let me add another silly question:

Does a complete template specialization require template<>? For example:


template<typename T>
class X {};

template<> // Is this strictly required?
class X<int> {};


It is not clear from the standard whether this is required, and G++ does not complain even in pedantic ISO mode.

Thank you.

Name: Anonymous 2012-01-20 7:28

Maybe

Name: Anonymous 2012-01-20 8:08

Tem plates are disgusting. Fuck a goat, ``please''

Name: Anonymous 2012-01-20 10:48

>Since C::method() is defined inside the class, it is defined as though as it were declared inline
What? Why? an inline need to have its implementation available for whoever is using it, but just because there's an implementation available doesn't mean that it will be inlined! So NO to both of your questions, because you haven't declared them as "inline".

Name: Anonymous 2012-01-20 12:32

>>5

Both your argument and conclusion are wrong.

C::method() is an inline function, as per C++03 9.3.2. "A member function may be defined (8.4) in its class definition, in which case it is an inline member function (...)".

And declaring a function as inline is not a guarantee that the function will be inline whatsoever. You actually got this right, but for the wrong reasons.

Name: Anonymous 2012-01-20 13:49

>>2
Member of an explicitly specialized class are defined the same way as members of a normal class. The standard provides this example:

template<class T> struct A {
    void f(T) { /* ... */ }
};

template<> struct A<int> {
    void f(int);
};

void h()
{
    A<int> a;
    a.f(16); // A<int>::f must be defined somewhere
}

// explicit specialization syntax not used for a member of
// explicitly specialized class template specialization
void A<int>::f() { /* ... */ }


Otherwise, you have to include template<>

Don't change these.
Name: Email:
Entire Thread Thread List