473,385 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

proper declaration for template link problem

Hi.

I'm stuck using a very old c++ compiler, and I'm trying to figure out how to
add a declaration so that an algorithm can be used. This is really a compiler
specific problem, however I was hoping someone could suggest the proper
declaration to put in place to solve it.

If someone can suggest a solution I'd really appreciate it.

Here is the scenario:

I have an object, and I use a vector and vector Iterator with it.

the old build system I'm using (borland 5.02) is set up
with the projects I'm stuck with to generate external references to all
template instances.

This requires that I put all template instances into a standalone cpp file
that is built differently so that they are all resolved to that cpp.

this works fine except when I add a call to:
sort(myvector.begin(),myvector.end()) or
find(myvector.begin(),myvector.end(),anObject)

I get unresolved linker errors.

Now I figure I need to add the sort and find functions to the .cpp file
that resolves all the other template components like vector.size() etc.

I can't figure out what to add though, to the file.

I tried adding things like:
std::find(MAnnotation*,MAnnotation*, const MAnnotation&);

because of the error description which said:
Error: Error: Unresolved external 'std::sort(MAnnotation*,MAnnotation*)'
referenced from module STLSortVectortester.cpp

but it did not resolve the link problem.

I appreciate any assistance.

Thanks
Jeff Kish
Oct 3 '06 #1
2 1916
On Tue, 03 Oct 2006 13:39:41 -0400, Jeff Kish <je*******@mro.comwrote:
>Hi.

I'm stuck using a very old c++ compiler, and I'm trying to figure out how to
add a declaration so that an algorithm can be used. This is really a compiler
specific problem, however I was hoping someone could suggest the proper
declaration to put in place to solve it.

If someone can suggest a solution I'd really appreciate it.

Here is the scenario:

I have an object, and I use a vector and vector Iterator with it.

the old build system I'm using (borland 5.02) is set up
with the projects I'm stuck with to generate external references to all
template instances.

This requires that I put all template instances into a standalone cpp file
that is built differently so that they are all resolved to that cpp.

this works fine except when I add a call to:
sort(myvector.begin(),myvector.end()) or
find(myvector.begin(),myvector.end(),anObject)

I get unresolved linker errors.

Now I figure I need to add the sort and find functions to the .cpp file
that resolves all the other template components like vector.size() etc.

I can't figure out what to add though, to the file.

I tried adding things like:
std::find(MAnnotation*,MAnnotation*, const MAnnotation&);

because of the error description which said:
Error: Error: Unresolved external 'std::sort(MAnnotation*,MAnnotation*)'
referenced from module STLSortVectortester.cpp

but it did not resolve the link problem.

I appreciate any assistance.

Thanks
Jeff Kish
I guess I'm tired.. this worked.
MAnnotation* std::find(MAnnotation*,MAnnotation*, const MAnnotation&);
I forgot that the return types are implictly int if I don't specify them which
was wrong.
Jeff Kish
Oct 3 '06 #2
Jeff Kish <je*******@mro.comwrote:
On Tue, 03 Oct 2006 13:39:41 -0400, Jeff Kish <je*******@mro.comwrote:
>>I'm stuck using a very old c++ compiler, and I'm trying to figure out how to
add a declaration so that an algorithm can be used. This is really a compiler
specific problem, however I was hoping someone could suggest the proper
declaration to put in place to solve it.

I tried adding things like:
std::find(MAnnotation*,MAnnotation*, const MAnnotation&);

because of the error description which said:
Error: Error: Unresolved external 'std::sort(MAnnotation*,MAnnotation*)'
referenced from module STLSortVectortester.cpp

but it did not resolve the link problem.

I guess I'm tired.. this worked.
MAnnotation* std::find(MAnnotation*,MAnnotation*, const MAnnotation&);
I forgot that the return types are implictly int if I don't specify them which
was wrong.
Maybe this is true since you must use an old compiler, but IIRC in
current C++ implicit return type is no longer supported... unfortunately
VS .NET 2003 SP1 has no qualms about compiling this code with all
warnings enabled; in fact, I couldn't even get it to warn me about
implicit int (if it did, it was buried underneath a bunch of warnings
for standard headers); of course, Comeau online gives the error:
explicit type is missing ("int" assumed).
#include <iostream>

f()
{
return 42;
}

int main()
{
f();
}

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Oct 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vlajko Knezic | last post by:
Not so sure what is going on here but is something to do with the way UTF8 is handled in Perl and/or LibXML The sctript below: - accepts a value from a form text field; - ...
2
by: jobseeker | last post by:
From: jobseeker95479@yahoo.com (jobseeker) Newsgroups: comp.lang.c++.moderated Subject: template and forward declaration NNTP-Posting-Host: 131.233.150.22 I have defined a class that contains a...
5
by: Nomak | last post by:
Hello all, i have two template classes which needs each other. I tried to write some fwd decl / decl / impl in a good way but i can't get it to compile. Explanations: - .hh files are for...
3
by: gugdias | last post by:
I'm coding a simple matrix class, which is resulting in the following error when compiling with g++ 3.4.2 (mingw-special): * declaration of `operator/' as non-function * expected `;' before '<'...
5
by: Mark Stijnman | last post by:
I am trying to teach myself template metaprogramming and I have been trying to create lists of related types. I am however stuck when I want to make a template that gives me the last type in a...
6
by: Hunk | last post by:
Hi I have a question on usage of forward declarations of templates. While searching through this group , people suggested using forward declarations and typedefs for templates as // in...
4
by: fdmfdmfdm | last post by:
I have the following code: #include <iostream> #include <cstdlib> #include <cassert> using namespace std; template <class T> class Stack{ public: enum{DefaultStack = 10, EmptyStack = -1};
2
by: Joseph Turian | last post by:
I have a class Feature defined, which is a kind of Vocab: template <class T, unsigned I> class Vocab : boost::totally_ordered<Vocab<T,I { public: Vocab(); Vocab(const T& t); template<typename...
2
by: Alan | last post by:
Does a template class declaration, like template <class T> have to come immediately prior to the declaration of the function, e.g., T do_something (T something) { . . . } that uses it?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.