Jack
Jack

Reputation: 25

What is the difference between these two methods of achieving a function call?

I'm slightly confused about what the difference between these two code examples are in C++. If anyone could explain it, it would be greatly appreciated.

class abc {
    void foo();
};

void abc::foo() {

}

versus something like:

class abc {
    void foo() {
        //func
    }
};

Upvotes: 0

Views: 80

Answers (2)

Some programmer dude
Some programmer dude

Reputation: 409482

The second alternative implicitly marks the function as inline, which means you can have it in a header file that is included into multiple translation units.

The first example would break the One Definition Rule if it were part of such a header file.

Upvotes: 2

Nikhil Badyal
Nikhil Badyal

Reputation: 1697

In the second case the function is by default inline but in other case you need to mention explicitly if you want it inline. Read about inline- Go there

Upvotes: 0

Related Questions