public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Should this compile and link??
@ 2002-01-16 12:34 Bill Priest
  2002-01-16 14:28 ` Ross Boylan
  0 siblings, 1 reply; 2+ messages in thread
From: Bill Priest @ 2002-01-16 12:34 UTC (permalink / raw)
  To: gcc-help

c4e3.cc
---------------
#include "c4e3.h"

int main(void)
{
	TEST_TYPE test1;

	test1.f1();
}
----------------
c4e3_func.cc
----------------
#include <cstdio>
#include "c4e3.h"

void TEST_TYPE::f1(void)
{
	puts("c4e3");
}
------------------

c4e3.h
------------------
#ifndef C4E3_H
#define C4E3_H

typedef struct // TEST_TYPE
{
	void f1(void);
} TEST_TYPE;

#endif
--------------------

w/ stock g++ 3.0.3 the following commands

g++    -c -o c4e3.o c4e3.cc
g++    -c -o c4e3_func.o c4e3_func.cc
g++ c4e3.o c4e3_func.o -o c4e3
c4e3.o: In function `main':
c4e3.o(.text+0x11): undefined reference to `TEST_TYPE::f1()'

If I uncomment TEST_TYPE in c4e3 everything compiles and links
as it should.

If I change c4e3.cc to include "c4e3_func.cc" and change the command to
g++ -o c4e3 c4e3.cc
then it compiles and links even if the c4e3.h file is unchanged (ie TEST_TYPE is commented out).

This doesn't make a whole lot of sense to me; but I'm not a C++ expert or even novice.  
Neither of my books (Thinking in C++ and C++ for C programmers) seems to cover this explicitly.

Is there something I'm missing here.  Scoping or namespace resolution was the only thing I could
come up with but didn't see anything in either of the books.

Please set me straight,

Bill

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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

end of thread, other threads:[~2002-01-16 22:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-16 12:34 Should this compile and link?? Bill Priest
2002-01-16 14:28 ` Ross Boylan

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).