Re: cout << char*
- From: Fil <Fil@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 25 Jun 2008 14:39:00 -0700
"Igor Tandetnik" wrote:
Fil <Fil@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
1) why do we include CLib.h in library.cpp while it is already
included in main.cpp
For the same reason you include <iostream> in both. Each source file is
compiled separately and doesn't know anything about other source files.
here CLib.h just contains the declarations of the definitions contained in
library.cpp
Including CLib.h in library.cpp is adding the declarations to the definitions.
For me it is equivalent to writing:
-----------------------------------------------------
int id(int);
int id(int a)
{
return a;
}
int main()
{
int a=3;
int b=id(a);
}
-----------------------------------------------------
here the id() declaraton is not necessary because we have the definition
before the main().
If I export the id() definition into another file I just have to make sure
the cpp were stands the main() has the declaration, while I don't care if the
cpp where stands the definition of id() has its declaration.
Or should I?
That was my question.
2) in order to print he content of intStash we did :
cout << *(int*)fetch(&intStash, i)
I see we are writing cout << (char*)fetch(&stringStash,i++) for the
structure containing arrays of char
Since cout is always able to display the char array ending with '\0'
when I pass to it a char* (cp in this case), how could I ask him to
display the address contained in cp?
Cast it to void*
thank you
With best wishes,.
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
- Follow-Ups:
- Re: cout << char*
- From: Igor Tandetnik
- Re: cout << char*
- From: Scott McPhillips [MVP]
- Re: cout << char*
- References:
- cout << char*
- From: Fil
- Re: cout << char*
- From: Igor Tandetnik
- cout << char*
- Prev by Date: Re: Exercise with array of pointers to func
- Next by Date: Re: cout << char*
- Previous by thread: Re: cout << char*
- Next by thread: Re: cout << char*
- Index(es):
Relevant Pages
|