If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

template error...

Hello everyone!
I'm trying to compile an old library that could be useful for my graphics project.
The code has been written by third-party years ago, and uses templates. Unfortunately I have never worked with templates, I just know that there are ... and I get many errors at compile time.
I try to post the code clearly.
[code

Re: template error...

Also, the std::pair is declared in the <map> header file.

My advice is to remove that old "pair" class altogether and use std::pair. Then fix the compiler errors when they occur, which shouldn't be difficult. The code will be smaller, shorter, and any competent C++ programmer will understand the code, instead of having to learn what this old, home-made "pair" class does.

Re: template error...

Also:

Code:

#include <iostream.h>

There is no such header file is <iostream.h>. The proper header is <iostream>, not <iostream.h>

Some advice: If you want to take old C++ code and use newer compilers on that code, be prepared to make wholesale changes. Things such as using the proper header files, using the standard classes instead of home-made ones, etc. requires that you know what you're doing without needing help.

Also, a lot of template code that compiled years ago on non-standard C++ compilers will no longer compile on standard compilers without having to make changes.

Re: template error...

Technically, you don't know if <map> includes the actual entire <utility> header, or just other sub headers, the strict necessary needed to find "std::map".

----
I'd add even more than that, you don't know if <map> even declares std::pair. Maybe it just forward declares it: even if it uses pair by value, since it's a template, that's good enough for a simple compilation, but if you want to use the actual methods that use pair (like insert) then you have to insert <utility> yourself.

The only thing I'm unsure of: Does the standard garantee that inlcuding a header is sufficient to compile everything in that header?

Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

Re: template error...

Originally Posted by mnty7

Hello everyone!
I'm trying to compile an old library that could be useful for my graphics project.

I'd suggest to completely rewrite the code if you do want to use it. There are many many things wrong in what you posted:
- no include guards in header files
- "using namespace" in a header file
- including non-standard headers
- no const-correctness
- there's no way to tell from the header file what functions do, as they don't even have named arguments
- exit is called upon a normal error
- unneeded use of macros

Cheers, D Drmmr

Please put [code][/code] tags around your code to preserve indentation and make it more readable.

As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Re: template error...

Thanks to everyone for the anwers!
I removed the "pair" template and adjusted the code to use std:air...it seems ok now.
But now i have to use the matrix template, but i have many many errors...
I totally agree with D_Drmmr, the best way would be rewrite the code...but I do not have the time or knowledge to rewrite a matrix class template...
It's possibile to correct this one?

Re: template error...

Originally Posted by mnty7

Thanks to everyone for the anwers!
I removed the "pair" template and adjusted the code to use std:air...it seems ok now.
But now i have to use the matrix template, but i have many many errors...
I totally agree with D_Drmmr, the best way would be rewrite the code...but I do not have the time or knowledge to rewrite a matrix class template...

Get a C++ matrix library that is already written. Something such as Blitz++, or many of the others that already exist.

It's possibile to correct this one?

Anything is possible, but why try to fix a buggy piece of code when you have well-established C++ template-based matrix libraries. All you need to do is install them, read the instructions, and start right away writing programs.

So is your goal to do matrix-based arithmetic, or spend (more likely, waste) time trying to get this to work (let alone compile)? If it's the former, get a library.

Seriously, it makes absolutely no sense to try and fix or rewite buggy C++ code you're not prepared to handle or understand. You have matrix libraries that already do what you want that are template-based, well-written, and relatively easy to use. If you need to look at how these libraries work, you have the source code available. So you're killing two birds with one stone -- a stable library that works, plus you get the source code to look at if you're interested.