Solved

C++ Container classes question (vectors, lists, etc)

Posted on 2004-03-28
19
547 Views
Last Modified: 2013-12-14
For some really weird reason I am getting 2 errors in my vector.h and list.h header files for the C++ container classes. I am using Borland C++ Builder, but that shouldn't make any difference I don't think.

The errors are both:

"Could not find a match for 'std::max( unsigned int, unsigned int)'."

And point to where vector.h, list.h, etc, call the max function (called as just max with no namespace before it). I think the max function it should be using is in algorith.h, but I'm not sure why I'm getting errors as I changed nothing in any of these files, and it worked alright before. I have also tried "using std::vector", but that doesn't help.

Thanks in advance for any help.
0
Comment
Question by:red_sodium
  • 7
  • 5
  • 4
  • +1
19 Comments
 
LVL 19

Expert Comment

by:mrwad99
ID: 10698413
If you post the offending code it would be useful :)
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 10698418
If you are not stating std::max then you can either fully qualify it or add

using std::max;

Either way, please post code :)
0
 
LVL 1

Author Comment

by:red_sodium
ID: 10698433
void initialize()
    {
        buffer_size =
           max((size_type)1,__RWSTD::__rw_allocation_size((value_type*)0,(size_type)0));
    }


That piece of code is in vector.h (~line 320 ), and it is the only line which gives me those 2 errors. The error does not appear when i only include vector.h, but it appears as soon as i define a vector:

vector<int> vInt;
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 10698443
>> when i only include vector.h

You should not be doing this, you should be stating

#include <vector>

And I would not assume that there is anything wrong with the source code for vector; messing with those can lead to infinite problems.
0
 
LVL 1

Author Comment

by:red_sodium
ID: 10698451
Sorry, meant #include <vector>

I am assuming it is something wrong with my code, but I can't see what could possibly be wrong.
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 10698463
OK.  I intially figured that the problem was when you try and call max(), but it know sounds like you get this "Could not find a match for 'std::max..." when you just declare a vector.  Correct ?

0
 
LVL 1

Author Comment

by:red_sodium
ID: 10698475
Yeah.
0
 
LVL 19

Expert Comment

by:mrwad99
ID: 10698500
Right that is very strange.  If you do not have another compiler paste your entire code here, or if you do try and compile it in that.
0
 
LVL 1

Author Comment

by:red_sodium
ID: 10698556
Sorry, it's too split up to post it all, but here's my includes.h header file:

#ifndef includesH
#define includesH

#include <vcl>
#include <windows>
#include <fstream>
#include <vector>
using std::vector;
#include "d3dx9.h"
#define WIN32_MEAN_AND_LEAN // Cut the fat from windows library

class EngineManager;
class DirectXSetup;

#include "defines.h"
#include "EngineManager.h"
#include "DirectXSetup.h"
//--------------------------------------------------------------------------
#endif


0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 19

Expert Comment

by:mrwad99
ID: 10698565
>> #include <windows>

should be #include <windows.h> but I don't think that will make a difference.

I cannot see why you are getting the error you are then, sorry.  Hope someone else can !

Will post again if any ideas crop up.
0
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 20 total points
ID: 10698959
Include <algorithm> and you should be sure to get the max template included.
0
 
LVL 19

Accepted Solution

by:
mrwad99 earned 30 total points
ID: 10699065
>> Include <algorithm>

hmm, not doing that in VC++ does not mean that I cannot declare a vector, but it may do in Borland.  We shall see...
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 20 total points
ID: 10699689
>>           max((size_type)1,__RWSTD::__rw_allocation_size((value_type*)0,(size_type)0));

That looks like a RoqueWave header of tools.h.

Is there any of the headers that include RoqueWave headers? I know they made a lot of messy defines to run their library with and without STL support. If so, you have a hard job if you couldn't eliminate these headers. You could try by moving

   using namespace std;

below all  includes and put private headers to the top or if  you could identify the wrong header (it uses old max macro) then do this

#ifndef max
#define max(a, b) ((a) < (b))? (b) : (a)

#include "header_file_using_RW"

#undef max
#endif

However these includes _MUST_ be above all STL includes.

Hope, that helps

Regards, Alex
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 10702668
>> Include <algorithm>
> hmm, not doing that in VC++ does not mean that I cannot declare a vector, but it may do in Borland.  We shall see...

I know it seems daft, but that's where the max template is defined and somehow or other you've not got it in your Borland setup.

I'd be wary of Alex's max macro. It could do unexpected things if the STL headers pass it a parameter with an increment operator.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10703524
>> I'd be wary of Alex's max macro. It could do unexpected things if the STL headers pass it a parameter with an increment operator.

That's right. That's why the macro __MUST__ be "#undef"ed before including any STL header.

Regards, Alex
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 10704072
Like...erm... <vector>??
0
 
LVL 1

Author Comment

by:red_sodium
ID: 10704965
Wow, this is so weird. It now works, without the need for any of these.

Could it be anything to do with my changing the priorities of my include folders, as this is the only thing I can think of which might have changed it...

Hmm, now I'm not sure what to do about the points...
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 10705014
I expect http:/Miscellaneous/Philosophy_Religion/ has the answer.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 10722943
>> Could it be anything to do with my changing the priorities of my include folders

That is most likely. If you have a mix between old libraries as RoqueWave tools.h and new(er) one like Borland C++ and STL you should make the newer ones to have higher priority.

Regards, Alex
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now