No Matching function error

This is a simplified version of an earlier post that went unanswered. I have tried to re-work things around without success. I still have no idea why the compiler recommends Vector<BoxMaker*> as a candidate. C++ is case sensitive yet I can create a vector with a line like:

Vector<int> test;

As a side note, I can "instantiate" the a MakeSmall object passing in no arguments even though its cstor is written to require one argument as you can see below. It does not even seem like that should compile!

Even if you don't know the answer, if you have any hunches please tell me anyway. This error has really been killing me. Thanks. BTW I am using DEV C++ IDE.

Error

In function `int main()':

no matching function for call to `MakeSmall::MakeSmall(std::vector<BoxMaker*, std::allocator<BoxMaker*> >)'

note candidates are: MakeSmall::MakeSmall(const MakeSmall&)

note MakeSmall::MakeSmall(Vector<BoxMaker*>)


Main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <vector>
#include "StartMeUp.h"
#include "Multiplier.h"
#include "Stroustrup.h"
#include "MakeSmall.h"
#include "BoxMaker.h"
using namespace std;

vector<int> g_Masks;
int g_Small;

int main()
try{
      StartMeUp KickStart;
      Multiplier MultiBox(KickStart.GetMyHosts());
      MakeSmall Shrinker(MultiBox.GetTheBoxSet()  );
      //LINE ABOVE IS FLAGGED BY COMPILER AS ERROR
    
    system("PAUSE");
    return 0;
}
...catch block not shown



MakeSmall.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef MakeSmall_h
#define MakeSmall_h
#include "SimpleBox.h"
#include "Token_stream.h"
#include "BoxMaker.h"
#include <vector>
using namespace std;

class MakeSmall
{
  public:
        MakeSmall(vector<BoxMaker*> Pass_in);
        vector<BoxMaker*> GetAltBoxSet();

 private:
         vector<BoxMaker*> BoxSet;
         int PureStack(vector<BoxMaker*> BoxSet);
         int SmallUpHigh(vector<BoxMaker*> BoxSet);
         int PureReserve(vector<BoxMaker*> BoxSet);
         int ReserveSmall(vector<BoxMaker*> BoxSet);
         int FigureMaxSNM(vector<SimpleBox*> myBoxes);
         vector<int> MaximumMasks; 
         

};
#endif


MakeSmall cstor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "MakeSmall.h"
#include "BoxMaker.h"
#include "SimpleBox.h"
#include <vector>
using namespace std;

MakeSmall::MakeSmall(vector<BoxMaker*> BoxSet_in):
                                                 BoxSet(BoxSet_in)
{
      vector<int> Masks;
      
      Masks.push_back(PureStack(BoxSet));
      Masks.push_back(SmallUpHigh(BoxSet));
                           
}  
Last edited on
Hi,

I'm not an expert but have been doing some stuff with vectors lately and was going to see if I could help.

With the problem line:
MakeSmall Shrinker(MultiBox.GetTheBoxSet() );

Do you have more information on what .GetTheBoxSet() does? i.e.: Function GetTheBoxSet() in class Multiplier? Maybe if you could post what that function looks like I can understand a bit more, thanks.
They might have their own type called 'Vector' which would be why it doesn't work...try searching for 'Vector' in their documentation or something.
If that Stroustrup.h is the file I think it is - then it looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// trivially range-checked vector (no iterator checking):
template< class T> struct Vector : public std::vector<T> {
	typedef typename std::vector<T>::size_type size_type;

	Vector() { }
	explicit Vector(size_type n) :std::vector<T>(n) {}
	Vector(size_type n, const T& v) :std::vector<T>(n,v) {}

	T& operator[](unsigned int i) // rather than return at(i);
	{
		if (i<0||this->size()<=i) throw Range_error(i);
		return std::vector<T>::operator[](i);
	}
	const T& operator[](unsigned int i) const
	{
		if (i<0||this->size()<=i) throw Range_error(i);
		return std::vector<T>::operator[](i);
	}
};

// disgusting macro hack to get a range checked vector:
#define vector Vector 


notice the line:
#define vector Vector
Ignore my previous post I got the answer to my question in another one of your posts, I think I was on the wrong track anywhere, as firedraco suggests check the docs, it looks like its picking up "Vector" from somewhere else, I can check it out since I have a different environment.
@guestgulkan...

Well done...that IS the file from Stroustrup's big blue text. (for those who don't know it is some error code used mainly with the try catch block for in-book examples) OK....so I guess that is why the compiler is saying I should try Vector with a capital V.

@Everyone....

But what about the cstor for MakeSmall? I still don't understand why the return value from GetTheBoxSet is not a good value to pass in to that cstor... Nor do I understand why a line like:
MakeSmall Shrinker();
will compile when the MakeSmall cstor requires one argument? There is something big (or small) I don't see, clearly.

I am going to post the Multiplier.h cstor on this thread as well so everyone can see GetTheBoxSet().

Multiplier.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef Multiplier_h
#define Multiplier_h
#include "Token_stream.h"
#include "BoxMaker.h"
#include <vector>
using std::vector;

class Multiplier
{
    public:
       Multiplier(vector<Token> hosts_in);
       vector<BoxMaker*> GetTheBoxSet();
    
    private:           
       vector<Token> hosts;
       vector<BoxMaker*> BoxSet;
};

#endif


GetTheBoxSet() in here...
1
2
3
4
5
6
7
8
9
10
#include "Multiplier.h"
#include "BoxMaker.h"
#include <vector>
using namespace std;

vector<BoxMaker*> Multiplier::GetTheBoxSet()
{
    return BoxSet;
}
Dammit. Was it necessary to make a separate thread?

Multiplier::GetTheBoxSet() is returning a vector<T>, which in the context of Multiplier.h means std::vector<T>. This context is kept when the file in included in main.cpp. In main.cpp, however, you try to assign this return value to a vector<T>, which in the context of main.cpp means Vector<T>, since there's a macro in effect turning vector into Vector.

It's like a bad coding practices salad!
Excellent. So now that it is known that the Stroustrup.h file includes a macro defining 'V'ector, can I make some alteration to main to make this work short of commenting out the offending line in Stroustrup.h?

@helios
I made the separate thread because no one replied to the first one. (until you did, but that was after the second thread was created.) I tried to make it shorter. I am new to forums and was not sure how much patience everyone generally has with reading through tons of included code. Looks like you were on the right track with your comment on the first thread. I was not even thinking about the Stroustrup include, but then again, I guess the bug is always where you are not looking. :)

As to "bad coding practices salad", I cannot defend myself on that charge as I am completely self-taught and still very much a novice. If you, or anyone else has any general recommendations or comments as to what makes the code so bad and how it might be improved I would love to hear about them. These forums are the only access I have to anyone who knows anything about C++ (or any other language for that matter).
Thanks for all the help.
As to "bad coding practices salad", I cannot defend myself
I meant it more as a critique on this:
#define one_identifier another_identifier
That's moronic. Specially when one_identifier happens to be defined in the std namespace.
Ugh.
OK....I commented out that section in Stroustrup.h and now it will compile. Is the fact that it would compile when I instantiated MakeSmall without passing an in argument related? This is really a subpoint, less important, but equally baffling.

@helios
Yeah, that code is a crutch to be used for the Stroustrup textbook that I managed to run afoul. I have not gotten around to writing my own try/catch routines and really have no idea what is in there. From where I sit it is still a black box.
Topic archived. No new replies allowed.