 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
JBorges Guest
|
Posted: Fri Jul 29, 2005 3:06 pm Post subject: problem using sets strings and namespaces |
|
|
I created a namespace Directory:
#include <set>
#include <string>
namespace Directory {
bool putInSet( const char *filename, std::set< std::string >
&setstrings );
}
the namespace has other functions, but they're irrelevant for now...
so, when I compile a file:
int main()
{
std::set< std::string > setstrings;
std::string filename( "anyfile" );
Directory::putInSet( filename.c_str(), setstrings );
return 0;
}
the gcc 3.3.5 ( using Linux ) shows the following error:
filesServer.cpp:(.text+0x192): undefined reference to
`Directory::putInSet(char const*, std::set<std::basic_string
std::char_traits,
std::less<std::basic_string
std::allocator<char> > >, std::allocator<std::basic_string
std::char_traits > >&)'
collect2: ld returned 1 exit status
We know that string::c_str() returns a const char *. Why, in the
message error the compiler shows char const * ? Anyone can give me a
solution?
|
|
| Back to top |
|
 |
Christian Meier Guest
|
Posted: Fri Jul 29, 2005 3:42 pm Post subject: Re: problem using sets strings and namespaces |
|
|
"JBorges" <joseborgesfilho (AT) gmail (DOT) com> schrieb im Newsbeitrag
news:1122649586.003947.113340 (AT) g14g2000cwa (DOT) googlegroups.com...
| Quote: | I created a namespace Directory:
#include <set
#include
namespace Directory {
bool putInSet( const char *filename, std::set< std::string
&setstrings );
}
the namespace has other functions, but they're irrelevant for now...
so, when I compile a file:
int main()
{
std::set< std::string > setstrings;
std::string filename( "anyfile" );
Directory::putInSet( filename.c_str(), setstrings );
return 0;
}
the gcc 3.3.5 ( using Linux ) shows the following error:
filesServer.cpp:(.text+0x192): undefined reference to
`Directory::putInSet(char const*, std::set<std::basic_string
std::char_traits,
std::less<std::basic_string
std::allocator<char> > >, std::allocator<std::basic_string
std::char_traits > >&)'
collect2: ld returned 1 exit status
We know that string::c_str() returns a const char *. Why, in the
message error the compiler shows char const * ? Anyone can give me a
solution?
|
You have no implementation for the function Directory::putInSet().
const char * is the same as char const * (but not the same as char * const).
|
|
| Back to top |
|
 |
JBorges Guest
|
Posted: Fri Jul 29, 2005 4:32 pm Post subject: Re: problem using sets strings and namespaces |
|
|
oops, I didn't write the implementation of the function but I did it in
my code. I only forget to write it in the post. So, consider the
function implemented in a file. In my code I did:
in the "directory.h" i put the declaration of the namespace Directory
and in the "directory.cpp" I put the implementation of the functions of
the namespace.
const char * IS NOT the same as char const *.
const char * ensures that the CONTENT of the pointer cannot be
modified, but the pointer can be modified. If we have
const char *s = "test";
we can do
while( *s != ' ' ) {
cout << *s;
++s;
}
but we cannot do
*s = 'q';
char const * ensures that the pointer cannot be modified ( it can only
point to a place where it was initialized )
char const *s = "test";
we cannot do
while (*s != ' ' ) ++s;
but we can do
*s = 'q';
Thank you, but my problem is still unresolved, and I don't know if it
is my error or a compiler error.
|
|
| Back to top |
|
 |
red floyd Guest
|
Posted: Fri Jul 29, 2005 4:35 pm Post subject: Re: problem using sets strings and namespaces |
|
|
JBorges wrote:
| Quote: |
const char * IS NOT the same as char const *.
const char * ensures that the CONTENT of the pointer cannot be
modified, but the pointer can be modified. If we have
char const * ensures that the pointer cannot be modified ( it can only
point to a place where it was initialized )
|
Wrong!
const char * = char const * = pointer to const char
char * const = const pointer to char.
|
|
| Back to top |
|
 |
Tobias Blomkvist Guest
|
Posted: Fri Jul 29, 2005 5:06 pm Post subject: Re: problem using sets strings and namespaces |
|
|
JBorges sade:
| Quote: |
const char * IS NOT the same as char const *.
|
As a complement to red floyd's answer, consult the
C++ Standard §8.3 Meaning of Declarators
Tobias
--
IMPORTANT: The contents of this email and attachments are confidential
and may be subject to legal privilege and/or protected by copyright.
Copying or communicating any part of it to others is prohibited and may
be unlawful.
|
|
| Back to top |
|
 |
JBorges Guest
|
Posted: Fri Jul 29, 2005 6:02 pm Post subject: Re: problem using sets strings and namespaces |
|
|
I was wrong. You're right.
thank you all. Maybe from now I can go on. Thanks again.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|