473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Inline member functions

I'm not sure if it violates standards or if it's just one of gcc's
quirks, but on gcc with Mac OS X (at least with my installation), for
some reason inline member functions that are not part of the class
declaration always produce linker errors.

For example, take a piece of my code:

// random access iterator for Cocoa Foundation's NSArray
// technically obj-c++, but only the c++ part that is relevant
class NSArrayIterator : std::iterator<...> {
// template arguments above not really relevant
unsigned int index;

public:
NSArrayIterator& operator++() { index++; return *this; }
};

The above compiles and links fine, but the one below gives out a linker
error

(NSArrayIterator.h)
class NSArrayIterator : std::iterator<...> {
unsigned int index;

//...
public:
NSArrayIterator& operator++();
};

(NSArrayIterator.mm)
inline NSArrayIterator& NSArrayIterator::operator++() {
index++;
return *this;
}

Is this supposed to be standard behavior (that it compiles but doesn't
link), a gcc quirk, or some other quirk? Is this issue similar to that
export and templates? If it's a gcc or linker thing, what should I set
in order for the second one to properly link?

--
I am only a mirage.
Jul 23 '05 #1
1 1594
On Mon, 06 Jun 2005 06:51:04 GMT, kelvSYC <ke*****@no.email.shaw.ca>
wrote in comp.lang.c++:
I'm not sure if it violates standards or if it's just one of gcc's
quirks, but on gcc with Mac OS X (at least with my installation), for
some reason inline member functions that are not part of the class
declaration always produce linker errors.

For example, take a piece of my code:

// random access iterator for Cocoa Foundation's NSArray
// technically obj-c++, but only the c++ part that is relevant
class NSArrayIterator : std::iterator<...> {
// template arguments above not really relevant
unsigned int index;

public:
NSArrayIterator& operator++() { index++; return *this; }
};

The above compiles and links fine, but the one below gives out a linker
error

(NSArrayIterator.h)
class NSArrayIterator : std::iterator<...> {
unsigned int index;

//...
public:
NSArrayIterator& operator++();
};

(NSArrayIterator.mm)
inline NSArrayIterator& NSArrayIterator::operator++() {
index++;
return *this;
}

Is this supposed to be standard behavior (that it compiles but doesn't
link), a gcc quirk, or some other quirk? Is this issue similar to that
export and templates? If it's a gcc or linker thing, what should I set
in order for the second one to properly link?


This is not similar to export for templates. The inline keyword
requests that the compiler substitute the executable code for the
function body in place of the call. It can do this if and only if it
has the source of the function in scope, to generate the code.

If you want the compiler to have the option of honoring your request
to inline the member functions, they need to be in the header.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Rubén Campos | last post by:
I haven't found any previous message related to what I'm going to ask here, but accept my anticipated excuses if I'm wrong. I want to ask about the real usefulness of the 'inline' keyword. I've...
3
by: Peng Yu | last post by:
Hi, I'm trying to define inline_test::test() to be inline. But I always got errors. I know that if I define inline_test::test() in inline_test.h, there are no errors. But I still would rather...
7
by: Srini | last post by:
Hello, Rules for inline functions say that they have to be defined in the same compilation unit as their declarations. For class member functions this means that the inline member functions must...
4
by: Tony Johansson | last post by:
Hello experts! I'm reading a book about C++ and there is something about inline that the book says that is unclear for me. The book says the following "Because inline functions are expanded at...
6
by: John Ratliff | last post by:
I was reading the C++ FAQ Lite about inline functions, and it says the following (http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.7) " It's usually imperative that the...
7
by: Wu Shaohua | last post by:
Hi Guys, 1. As we know usually we should not define a constructor as inline. I also learned if we define a member function inside the class this member function will be automatically be...
9
by: lucifer | last post by:
Hi I have a little problem regarding inline functions ,does declaring a function inside the class definition make it inline or not.
2
by: Nagrik | last post by:
Dear Group, The book of Bjarne Stroustrup in chapter 5.4.4 says the following "The word static is one of the most overused words in C and C++. For static data members it has both of the...
17
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.