T
Thomas Matthews
Hi,
I'm getting linking errors when I declare a variable in the
global scope, but not inside a function. The declarations
are the same (only the names have been changed...).
class Book
{
public:
Book()
{ ; }
virtual ~Book() { ; }
string get_title(void) const
{ return title;}
private:
std::string title;
std::string author;
};
/* Global scope declaration */
Book Global_Book;
/* Inside function declaration */
void Any_Function(void)
{
static std::string book_title;
Book any_book;
book_title = any_book.get_title();
return;
}
I am throwing this code into a library, and the library
reports:
U global destructors keyed to Global_Book
U global constructors keyed to Global_Book
If I comment-out the global declaration, these messages
disappear {of course}.
So, why are there constructors & destructors for a global
instance, but not for an instance local to the function?
If I change the declaration of "any_book" in the function
to static, there are still no "global constructors" listed
for it (I would think there would be).
I am using g++ (GCC) 3.3.1 (cygming special).
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
I'm getting linking errors when I declare a variable in the
global scope, but not inside a function. The declarations
are the same (only the names have been changed...).
class Book
{
public:
Book()
{ ; }
virtual ~Book() { ; }
string get_title(void) const
{ return title;}
private:
std::string title;
std::string author;
};
/* Global scope declaration */
Book Global_Book;
/* Inside function declaration */
void Any_Function(void)
{
static std::string book_title;
Book any_book;
book_title = any_book.get_title();
return;
}
I am throwing this code into a library, and the library
reports:
U global destructors keyed to Global_Book
U global constructors keyed to Global_Book
If I comment-out the global declaration, these messages
disappear {of course}.
So, why are there constructors & destructors for a global
instance, but not for an instance local to the function?
If I change the declaration of "any_book" in the function
to static, there are still no "global constructors" listed
for it (I would think there would be).
I am using g++ (GCC) 3.3.1 (cygming special).
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library