This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Bug in g++ 4.1.2 when using inline function definied in cpp file but declared in h file


hi
i found bug in g++ 4.1.2 - version included with new kubuntu fiesty.
to reproduce this bug i've created 3 simple files a.h, a.cpp and main.cpp

//a.h
#ifndef A_H
#define A_H
class A{
public:
	void b(int c);
private:
int d;
};
#endif 

//a.cpp
#include "a.h"
inline void A::b(int c)
{
	d = c;
}

//main.cpp
#include "a.h"
int main()
{
	A *a = new A;
	a->b(1);
	return 0;
} 


then when i'm compiling them :
g++ -c -o a.o a.cpp - everything is ok
g++ -o A a.o main.o - i get:

main.o: In function `main':
main.cpp:(.text+0x2f): undefined reference to `A::b(int)'
collect2: ld returned 1 exit status

when i add those 2 lines to a.cpp:
#pragma implementation
#pragma interface

so it looks like this:

//a.cpp
#include "a.h"
#pragma implementation
#pragma interface
inline void A::b(int c)
{
	d = c;
}

everything is ok. i tried every possible combination of those pragmas and 
inline kayword, but only this one seams to work.

bartosz wadolowski


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]