I have the following 2 files as part of my project:
GenFuncs.h
------------
#ifndef GenFuncsH
#define GenFuncsH
#include <iostream.h>
#include <strstream.h>
using namespace std;
//template <class T> string str(T In);
string Int2Hex(int In);
template <class T> string str(T In) {
ostrstream oss;
oss << In;
return(oss.str());
}
#endif
GenFuncs.cpp
------------
#pragma hdrstop
#include "GenFuncs.h"
#pragma package(smart_init)
string Int2Hex(int In) {
ostrstream oss;
oss << hex << In;
return(oss.str());
}
Now, if I compile this code "as is" in Borland, it compiles OK, and I am
able to use both the Int2Hex() and str() functions in my other code that
#includes GenFuncs.h.
Problem #1
when I try to compile in gnu with:
g++ -g -c GenFuncs.cpp
I get
GenFuncs.h:8 syntax error before '(' // This is the declaration for Int2Hex
It seems that it does not recognize the string identifier (which I don't
understand, because I am using namespace std)
Problem #2
Ideally, I would like to have the declaration for the str() function in the
GenFuncs.h file and the body in the GenFuncs.cpp file. However, if I do
this (uncomment the declaration and move the body to .cpp), then I get
linker errors in Borland like thus:
[Linker Error] Unresolved external 'std::basic_string<char,
std::char_traits<char>, std::allocator<char> > str<double>(double)'
referenced from C:\PROGRAMS\PROJ\TESTCLASS.OBJ.
I get a linker error for each function call to the template function. Note
that if I replace the template declaration and body with overloaded
non-template versions, then it compiles fine.
Any help is appreciated...
Vic 7 3625
Victor Hannak wrote: I have the following 2 files as part of my project:
GenFuncs.h ------------ #ifndef GenFuncsH #define GenFuncsH #include <iostream.h>
#include <iostream> // iostream.h is deprecated - don't used them
#include <strstream.h> using namespace std;
//template <class T> string str(T In); string Int2Hex(int In);
template <class T> string str(T In) { ostrstream oss; oss << In; return(oss.str()); }
#endif
GenFuncs.cpp ------------ #pragma hdrstop #include "GenFuncs.h" #pragma package(smart_init) string Int2Hex(int In) { ostrstream oss; oss << hex << In; return(oss.str()); }
Now, if I compile this code "as is" in Borland, it compiles OK, and I am able to use both the Int2Hex() and str() functions in my other code that #includes GenFuncs.h.
Problem #1
when I try to compile in gnu with:
g++ -g -c GenFuncs.cpp
I get
GenFuncs.h:8 syntax error before '(' // This is the declaration for Int2Hex
It seems that it does not recognize the string identifier (which I don't understand, because I am using namespace std)
Problem #2
Ideally, I would like to have the declaration for the str() function in the GenFuncs.h file and the body in the GenFuncs.cpp file. However, if I do this (uncomment the declaration and move the body to .cpp), then I get linker errors in Borland like thus:
[Linker Error] Unresolved external 'std::basic_string<char, std::char_traits<char>, std::allocator<char> > str<double>(double)' referenced from C:\PROGRAMS\PROJ\TESTCLASS.OBJ.
I get a linker error for each function call to the template function. Note that if I replace the template declaration and body with overloaded non-template versions, then it compiles fine.
Any help is appreciated...
Try this. It may solve problem 2, if not then I suggest you contact a
borland NG.
::::::::::::::
GenFuncs.h
::::::::::::::
#ifndef GenFuncsH
#define GenFuncsH
#include <iostream>
#include <sstream>
using namespace std;
//template <class T> string str(T In);
string Int2Hex(int In);
template <class T> string str(T In) {
ostringstream oss;
oss << In;
return(oss.str());
}
#endif
::::::::::::::
GenFuncs.cpp
::::::::::::::
#pragma hdrstop
#include "GenFuncs.h"
#pragma package(smart_init)
string Int2Hex(int In) {
ostringstream oss;
oss << hex << In;
return(oss.str());
}
Victor Hannak wrote: I have the following 2 files as part of my project:
GenFuncs.h ------------ #ifndef GenFuncsH #define GenFuncsH #include <iostream.h>
No such header in standard C++ (iostream.h is a holdover from
pre-standard days).
#include <iostream>
#include <strstream.h>
Similarly.
#include <sstream>
For the error below:
#include <string>
using namespace std;
Putting a using directive like this in a header is a Bad Idea, as it
pollutes the namespace in a way that might not be immediately
apparent. It would be better to use fully qualified names. //template <class T> string str(T In); string Int2Hex(int In);
You didn't include <string>. See above. template <class T> string str(T In) { ostrstream oss; oss << In; return(oss.str()); }
#endif
GenFuncs.cpp ------------ #pragma hdrstop
Non standard. Please remove non standard things from code you post
to news:comp.lang.c++.
#include "GenFuncs.h" #pragma package(smart_init) string Int2Hex(int In) { ostrstream oss; oss << hex << In; return(oss.str()); }
Now, if I compile this code "as is" in Borland, it compiles OK, and I am able to use both the Int2Hex() and str() functions in my other code that #includes GenFuncs.h.
Problem #1
when I try to compile in gnu with:
g++ -g -c GenFuncs.cpp
I get
GenFuncs.h:8 syntax error before '(' // This is the declaration for Int2Hex
It seems that it does not recognize the string identifier (which I don't understand, because I am using namespace std)
But you didn't `#include <string>" Problem #2
Ideally, I would like to have the declaration for the str() function in the GenFuncs.h file and the body in the GenFuncs.cpp file. However, if I do this (uncomment the declaration and move the body to .cpp), then I get linker errors in Borland like thus:
[Linker Error] Unresolved external 'std::basic_string<char, std::char_traits<char>, std::allocator<char> > str<double>(double)' referenced from C:\PROGRAMS\PROJ\TESTCLASS.OBJ.
I get a linker error for each function call to the template function. Note that if I replace the template declaration and body with overloaded non-template versions, then it compiles fine.
Since your compilers do not support the `export' keyword (few do,
only Comeau comes to mind, though I think there may be others), all
templated code must be visible in any translation unit in which it
is used.
HTH,
--ag
--
Artie Gold -- Austin, Texas
Victor Hannak wrote: I have the following 2 files as part of my project:
GenFuncs.h ------------ #ifndef GenFuncsH #define GenFuncsH #include <iostream.h>
Non-standard header. Use <iostream> instead.
#include <strstream.h>
Non-standard header. Use <sstream>.
using namespace std;
Bad idea in a header file. The person #including your header may not
want the entire std namespace included. //template <class T> string str(T In); string Int2Hex(int In);
What is 'string'? If you mean std::string, you'd better include the
appropriate header (<string>). template <class T> string str(T In) { ostrstream oss;
Use std::ostringstream instead.
oss << In; return(oss.str()); }
#endif
GenFuncs.cpp ------------ #pragma hdrstop
This is non-standard.
#include "GenFuncs.h" #pragma package(smart_init)
This is non-standard.
string Int2Hex(int In) { ostrstream oss; oss << hex << In; return(oss.str()); }
Now, if I compile this code "as is" in Borland, it compiles OK,
That would be luck.
and I am able to use both the Int2Hex() and str() functions in my other code that #includes GenFuncs.h.
Problem #1
when I try to compile in gnu with:
g++ -g -c GenFuncs.cpp
I get
GenFuncs.h:8 syntax error before '(' // This is the declaration for Int2Hex
It seems that it does not recognize the string identifier (which I don't understand, because I am using namespace std)
That isn't the issue. 'using namespace std' does not tell the compiler
what 'string' is. You do that by #including <string>. Problem #2
Ideally, I would like to have the declaration for the str() function in the GenFuncs.h file and the body in the GenFuncs.cpp file.
Read a little bit about templates. Unless your compiler supports
'export' (I only know of 1 that does), you are out of luck. http://www.parashift.com/c++-faq-lit...html#faq-34.13
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Thanks for the great suggestions, they helped me get over those hurdles.
However, there is something that is unclear to me in all of this...
You all told me to use the <sstream> header in conjunction with the
ostringstream type. This worked fine in Borland, but gnu choked. However,
when I switched back to <strstream> and ostrstream, both compilers accepted
it just fine. Of course my C++ textbook (C++ How to Program by
Deitel/Deitel) still uses the <strstream.h> notation. Can someone just
comment on the difference between <strstream> and <sstream>.
After looking at bok reviews on www.accu.org, I am thinking that "The C++
Programming Language Special Edition", by Bjarne Stroustrup seems like my
best bet for an updated C++ general reference book. Does this sound right?
> After looking at bok reviews on www.accu.org, I am thinking that "The
C++ Programming Language Special Edition", by Bjarne Stroustrup seems like
my best bet for an updated C++ general reference book. Does this sound
right?
Yes.
--
Peter van Merkerk
peter.van.merkerk(at)dse.nl
Victor Hannak escribió: You all told me to use the <sstream> header in conjunction with the ostringstream type. This worked fine in Borland, but gnu choked. However, when I switched back to <strstream> and ostrstream, both compilers accepted
If you have an old version of gcc you can download a sstream file from
gcc.gnu.org (the address is in the faq of the site, I think), is not a
complete standard implementation but works in many uses.
Regards.
Gianni Mariani wrote: #include <iostream> // iostream.h is deprecated - don't used them
Actually, it's not deprecated. It's ignored. <g> In the standard,
"deprecated" means that something is currently part of the language, but
you're warned that it may go away in a subsequent version of the
standard. Since iostream.h was never part of the C++ standard, there's
nothing to deprecate.
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: lmckaha |
last post by:
Hi,
Mysql version: 3.23.49
Solaris version: 2.7
gcc compiler version: 2.95.2
Python : 2.2.2
I'm evaluating the C and C++ API to decide which one to bye but I have
many troubles.
|
by: Jordan Willms |
last post by:
My xsl stylesheet is as simple as follows:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:ims="http://www.imsglobal.org/xsd/imsmd_v1p2"...
|
by: Brice Prunier |
last post by:
Here under 4 schemas i'm working with ( it may be long: sorry...)
The context is the following :
Resident.xsd imports Person.xsd and includes Common.xsd ( anonimous schema:
no TargetNamespace )...
|
by: Chris LaJoie |
last post by:
Our company has been developing a program in C# for some time now, and we
haven't had any problems with it, but just last night something cropped up
that has me, and everyone else, stumped.
I...
|
by: Gustavo |
last post by:
After updating Windows 2000 I began to get a weird compile
error message:
Deleting intermediate files and output files for
project 'pp - Win32 Debug'.
--------------------Configuration: pp -...
| |
by: Tim |
last post by:
hi, I'm wondering if anyone else has seen this. I've just built and
published a web site on my developer machine, then copied the
precompiled web to a staging / test machine. The code runs fine on...
|
by: Arne |
last post by:
I am porting a website to ASP.net 2.0. Temporarily I compile with Visual
Studio 2003 and deploying to ASP.net 2.0. How do I compile my website under
ASP.Net 2.0? I know it can compile each page as...
|
by: rdemyan via AccessMonster.com |
last post by:
I have a launcher program that creates the shortcut to open my application
using the Shell command. On the form I have a decompile checkbox that I can
conveniently use to decompile my program. I...
|
by: steve yee |
last post by:
i want to detect if the compile is 32 bits or 64 bits in the source
code itself. so different code are compiled respectively. how to do
this?
|
by: CodeMonk3y |
last post by:
gotta question on sizeof keyword
does the sizeof keyword calcuates the size at compile time or run time ??
-- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |