Re: newbie question



You need to do the include anywhere you want to reference the variable, but
if you want to use the same variable in another file then put an "extern" in
front of the declaration so the compiler knows it's created elsewhere.
Othewise you will end up with two variables with the same name.

Tom

"Mark1110" <Mark1110@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F11815BD-0A3F-426D-B0B7-85B3901395DE@xxxxxxxxxxxxxxxx
Hi,

I am relativly new to VC++. I have a source file called complx.cpp.
Because
I want to print to a text file, I have the following statements in the
.cpp
file:

# include <fstream.h>
ofstream echo("c:\\output.txt", ios::app);

I also have another file called funct.cpp which has member functions in
it.
For some reason I can't compile it unless I use the above statements in
the
source. When I try an link the files I get an error message saying echo is
already defined in complx.obj. I have been racking my brains trying to
figure
out a way to make it work. Can someone tell me what I need to do to make
it
link correctly. Both .cpp files are in my project.

Thanks,

Mark


.



Relevant Pages

  • Re: Question about External References
    ... a C++ guru and a Python expert, and I'm just now ramping up on C#. ... when one source file needs to refer to things compiled in another ... we have to use prototypes and declarations to let the compiler ... As the compilation is done in stages, every reference doesn't have to be specified for each file that is compiled. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to set my own program startup in f77 programs other than MAIN__
    ... But we don't have the source file where ... whatever they call it these days) compiler. ... I think the whole approach of stuffing your initializer into a ... "Operation of the Runtime Linker ...
    (comp.lang.fortran)
  • Re: runtime identification of compiler through executable
    ... i need to use this information in a source file ... ... You could try the "strings" command, ... the compiler at the top, ... and its original path. ...
    (comp.unix.aix)
  • Re: Getting source file from the object file
    ... is the output of a particular compiler whose output is a deterministic ... some source file which when compiled by that compiler ... machine code, and include the machine code as a static array. ...
    (comp.lang.c)
  • Re: Getting source file from the object file
    ... is the output of a particular compiler whose output is a deterministic ... some source file which when compiled by that compiler ... machine code, and include the machine code as a static array. ...
    (comp.lang.c)