funzione inline

A

andrew

Ciao,

Ho fatto una classe in C++, sia Rubrica il nome della classe.
Poi ho fatto creato una funzione membro


int Rubrica::getNumber(void)
{
return number;
}

il prototipo di questa funzione membro è int getNumber(void);

Poi mi sono posto il problema di rendere questa funzione inline,
e per fare ciò ho scritto:

inline int Rubrica::getNumber(void)
{
return number;
}

quando, dopo aver istanziato un oggetto della classe Rubrica ho
invocato la funzione getNumber non ho utilizzato la sintassi inline.

Il compilatore si lamenta... dove sbaglio?


Grazie, ciao
 
J

James Kanze

Ho fatto una classe in C++, sia Rubrica il nome della classe.
Poi ho fatto creato una funzione membro
int Rubrica::getNumber(void)
{
return number;
}
il prototipo di questa funzione membro è int getNumber(void);
Poi mi sono posto il problema di rendere questa funzione
inline, e per fare ciò ho scritto:
inline int Rubrica::getNumber(void)
{
return number;
}
quando, dopo aver istanziato un oggetto della classe Rubrica
ho invocato la funzione getNumber non ho utilizzato la
sintassi inline.
Il compilatore si lamenta... dove sbaglio?

Posting in Italian in an English speaking group, and expecting
to be understood.

Beyond that, it's not clear what your problem is. Who didn't
use the inline syntax? If you defined the function as above,
you used the inline syntax. And the compiler doesn't "use"
syntax, it interprets it. If the question is: why didn't the
compiler generate the function inline, that answer is: because
it didn't. Inline doesn't guarantee anything, and a lot of
compilers (e.g. g++) don't generate code inline unless
some optimization is requested. If you're getting a compiler
error, however, which seems to be the case, it's probably that
you've declared the function inline, but not defined it in the
translation unit where it is used. (But you've not posted
enough of the context to be sure.)
 
A

andrew

Posting in Italian in an English speaking group, and expecting
to be understood.

Beyond that, it's not clear what your problem is.  Who didn't
use the inline syntax?  If you defined the function as above,
you used the inline syntax.  And the compiler doesn't "use"
syntax, it interprets it.  If the question is: why didn't the
compiler generate the function inline, that answer is: because
it didn't.  Inline doesn't guarantee anything, and a lot of
compilers (e.g. g++) don't generate code inline unless
some optimization is requested.  If you're getting a compiler
error, however, which seems to be the case, it's probably that
you've declared the function inline, but not defined it in the
translation unit where it is used.  (But you've not posted
enough of the context to be sure.)

--
James Kanze (GABI Software)             email:[email protected]
Conseils en informatique orientée objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34- Nascondi testo citato

- Mostra testo citato -

Well:
----- main.c file ---

#include <stdio.h>
#include <stdlib.h>


#include "Multiplication.h"


int main()
{
int f1, f2, prodotto;


printf("Inserire un valore intero per il primo fattore:\n");
scanf("%d", &f1);


printf("Inserire un valore intero per il secondo fattore:
\n");
scanf("%d", &f2);


Multiplication obj;


prodotto = obj.molt(f1, f2);


printf("Il prodotto tra i due fattori e\' %d\n", prodotto);


system("pause");
return 0;



}


----------Multiplication.cpp file----------

#include <stdio.h>
#include <stdlib.h>


#include "Multiplication.h"


inline int Multiplication::molt(int a, int b)
{
int result;


result = a * b;
return result;



}


----------------Multiplication.h file----------------

class Multiplication
{
public:
int molt(int a, int b);



};

-------first error put in evicdence by microsoft visual studio
2008 :--------

error LNK2019: riferimento al simbolo esterno "public: int __thiscall
Multiplication::molt(int,int)"
(?molt@Multiplication@@QAEHHH@Z) non risolto nella funzione _main

-------second error put in evicdence by microsoft visual studio
2008 :--------


fatal error LNK1120: 1 esterni non risolti


Who help me in finding out all the errors in my source files ?
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top