Funções inline

1. Funções inline

RCA
RCA_ITA

(usa Ubuntu)

Enviado em 01/02/2009 - 13:33h

OI pessoal!!

Estou estudando c++ e estou com uma problema.
tenho uma classe A

//A.h

class A{
int a

inline set(int,int);

}

ai criei um arquivo de implementação da classe A.cpp
só que quando chamo a função diz a seguinte mensagem
A.h:17: warning: inline function ‘void A::set(int, int)’ used but never defined

no entanto li num apostila bem popular da net que impĺementa a função em um arquivo .cpp, mas aqui não funcionou.



  


2. Re: Funções inline

Marcelo A. B. Slomp
mslomp

(usa Slackware)

Enviado em 01/02/2009 - 20:57h

há um tempo atrás houve aqui uma questão sobre funções inline, e na ocasião eu e outros colegas do vol discorremos sobre o assunto:

http://www.vivaolinux.com.br/topico/C-C++/Problema-funcao-inline

atente especificamente nos posts que falam sobre a necessidade da implementação estar no mesmo arquivo-fonte que o protótipo e também sobre como instruir o gcc a efetivamente transformar sua função em inline.


3. Re: Funções inline

Frederico Cassis
fredcrs

(usa Debian)

Enviado em 06/02/2009 - 23:44h

inline set(int,int);
??
nao faltou um void ai nao??

inline void set(int,int);


4. Re: Funções inline

RCA
RCA_ITA

(usa Ubuntu)

Enviado em 07/02/2009 - 10:05h

Eu defini e implementei a função inline no próprio .h e não no .cpp.

Dai conclui que funções inline devem ser implementadas nos arquivos .h , certo?



5. Re: Funções inline

Frederico Cassis
fredcrs

(usa Debian)

Enviado em 09/02/2009 - 09:52h

achei isso aqu no google mas eu achava q no .h tbm tinha q botar inline:


When you declare an inline member function, it looks just like a normal member function:

class Fred {
public:
void f(int i, char c);
};

But when you define an inline member function, you prepend the member function's definition with the keyword inline, and you put the definition into a header file:

inline
void Fred::f(int i, char c)
{
...
}

It's usually imperative that the function's definition (the part between the {...}) be placed in a header file. If you put the inline function's definition into a .cpp file, and if it is called from some other .cpp file, you'll get an "unresolved external" error from the linker.