public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* c++ compilation error (undefined reference)
@ 2002-10-27 16:48 Baraclese
  2002-10-28  3:12 ` Andrea Bocci
  0 siblings, 1 reply; 2+ messages in thread
From: Baraclese @ 2002-10-27 16:48 UTC (permalink / raw)
  To: gcc-help

Hi, I wrote a TGA header file and I wanted to test it with a small main 
file.
tga.h looks something like this:
class TGA
{
	public:
	
		TGA();
		TGA(char *filename);
		~TGA();
		
		bool load(char const *filename);
}

tga.cpp looks like this:

#include "tga.h"
using namespace std;

main()
{
	TGA image;
	
	cout << "Filename: ";
	cin >> image.filename;
	
	if (image.load(image.filename))
		cout << "File successfully read./n";
	return 0;
}

When compiling using gcc 3.2 I receive the following error message:

$ g++ -mno-cygwin -lstdc++ f:/projects/cpp/tga.cpp -o tga.exe
/cygdrive/c/WIN98/TEMP/cccSDKcK.o(.text+0x9f0):tga.cpp: undefined 
reference to `TGA::TGA()'

What's the problem here?

regards,
Baraclese

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: c++ compilation error (undefined reference)
  2002-10-27 16:48 c++ compilation error (undefined reference) Baraclese
@ 2002-10-28  3:12 ` Andrea Bocci
  0 siblings, 0 replies; 2+ messages in thread
From: Andrea Bocci @ 2002-10-28  3:12 UTC (permalink / raw)
  To: Baraclese; +Cc: gcc-help

The compiler is telling you that it cannot find the TGA constructor. Well, 
can't blame it, you didn't provide one :-)
IIRC, to get the default constructor (doing nothing but allocating the 
class itself, more or less) and esructor (idem), you sould not declare them.
If you do, the compiler expect you do define them, too, hence the link error.

fwyzard

At 01.48 28/10/2002 +0100, Baraclese wrote:
>Hi, I wrote a TGA header file and I wanted to test it with a small main file.
>tga.h looks something like this:
>class TGA
>{
>         public:
>
>                 TGA();
>                 TGA(char *filename);
>                 ~TGA();
>
>                 bool load(char const *filename);
>}
>
>tga.cpp looks like this:
>
>#include "tga.h"
>using namespace std;
>
>main()
>{
>         TGA image;
>
>         cout << "Filename: ";
>         cin >> image.filename;
>
>         if (image.load(image.filename))
>                 cout << "File successfully read./n";
>         return 0;
>}
>
>When compiling using gcc 3.2 I receive the following error message:
>
>$ g++ -mno-cygwin -lstdc++ f:/projects/cpp/tga.cpp -o tga.exe
>/cygdrive/c/WIN98/TEMP/cccSDKcK.o(.text+0x9f0):tga.cpp: undefined 
>reference to `TGA::TGA()'
>
>What's the problem here?
>
>regards,
>Baraclese


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-10-28 11:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-27 16:48 c++ compilation error (undefined reference) Baraclese
2002-10-28  3:12 ` Andrea Bocci

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).