no matching function for call to classname::classname

I get the following error generated from the cstor of the StartMeUp class.

no matching function for call to BoxMaker::BoxMaker
note candidates are: BoxMaker::BoxMaker(const BoxMaker&)
note BoxMaker::BoxMaker(std::vector<Token, std::allocator<Token> >)

As far as I understand things, I am not making a call to the BoxMaker class from the cstor of StartMeUp. After the error I included BoxMaker.h just in case. It did not help anything.

Below is the StartMeUp cstor and header file as well as the .h file for BoxMaker. Thanks in advance for all the help. Also, I am very open to general recommendations about "good practice" and design. I am very much still on the steep part of the learning curve.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//STARTMEUP CONSTRUCTOR
#include "StartMeUp.h"
#include "Token_stream.h"
#include "BoxMaker.h"
#include <vector>
using std::vector;

StartMeUp::StartMeUp()
{
  //DEBUGGER FLAGS THIS BLANK LINE WITH THE ERROR
    LanCalc();
    vector<Token> LocalHosts;
    LocalHosts    =     GetHosts(); 
    LocalHosts = GetTestTemplate(LocalHosts); 
    int MaximumMask = CalcMaxSNM(Hosts);    
    
    BaseIP  =     GetOctets2( Hosts, MaximumMask);
    NetworkBits = ConvertToNetworkBits( BaseIP);
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//BOXMAKER HEADER FILE
#ifndef BoxMaker_h
#define BoxMaker_h
#include "SimpleBox.h"
#include "Token_stream.h"
#include <vector>

class BoxMaker
{
  public:
         BoxMaker (vector<Token> Hosts_in);
         void PRINT_TEST();
         vector<SimpleBox*> GetMyBoxes();
         vector<Token> GetMyTokens();
        // BoxMaker GetCopy();
         
  private:
          vector<Token> theHosts;
          vector<SimpleBox*> myBoxes;
          
};

#endif



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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//STARTMEUP HEADER FILE
#ifndef StartMeUp_h
#define StartMeUp_h
#include "Token_stream.h"
#include "BoxMaker.h"
#include <vector>

using std::vector;

class StartMeUp
{
public:
        StartMeUp();
        vector<Token>  GetMyHosts();
        vector<Token>  GetMyBaseIP(); 
        vector<int>    GetMyNetworkBits();
        Token          INeedTheTemplate();
private:
        
        Token   theTestTemplate;
        vector<Token>    GetTestTemplate( vector<Token> ); 
        void Delay(int=75000000);
        void LanCalc();
        
        void GetTheBoxBot();
        BoxMaker myBoxMaker;       
        Token   theTemplate;
        vector<Token> TokenSorter(vector<Token> Hosts);
        vector<Token> GetNumber(bool, vector<Token>, int, char SNM = '*', int MaxSNM = 30);
        vector<Token> GetNumberAndDot(bool broken, vector<Token> Octets, int limit);  
        vector<Token>  GetHosts();
        vector<Token>  GetOctets2(vector<Token>, int );
        vector<int>    ConvertToNetworkBits(vector<Token>);
        int GetBlockSize(int);
        void GetTemplate(); 
        void DefineSmall();        
        int CalcMaxSNM(vector<Token> );
        void LaunchHelp();
        
        vector<Token>  BaseIP;           //4 octets + the SNM
        vector<Token>  Hosts;            //hosts + max allowable SNM
        vector<int>    NetworkBits;
};
#endif





Last edited on
You are trying to call BoxMaker's default constructor (see line 26, just above) but by declaring a user-defined
constructor for BoxMaker you no longer get a default constructor provided by the compiler.

Example:
1
2
3
4
5
6
7
8
9
10
11
class Foo {
  private:
      std::string aString;

  public:
      Foo( const std::string& str )
          // Compiler tries to call std::string::string() constructor for aString here
      {
           aString = str;
       }
};


The above works since std::string() has a default constructor. You can specify to call a different
constructor this way:

1
2
3
4
5
6
7
8
9
10
class Foo {
  private:
      std::string aString;

  public:
      Foo( const std::string& str )
          : aString( str )  // Specify to call std::string copy constructor instead to copy str to aString
      {
       }
};


Read up on initializer lists (the part after the colon) if you are not familiar.
I am familiar with member initializer lists. But are you saying that they have to be used in the declaration of the user defined constructor (my .h file) as well as the definition of the user defined cstor as well (my related .cpp file) ??

but by declaring a user-defined
constructor for BoxMaker you no longer get a default constructor provided by the compiler.


This I understand, but since I wrote my own constructor, why would this matter?

Here is the cstor of the BoxMaker class.

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
#include "BoxMaker.h"
#include <vector>

BoxMaker::BoxMaker(vector<Token> Hosts_in):
                                          theHosts(Hosts_in)
{   
    int numOfSubnets;
    int h;
    int lasttoken = theHosts.size()-1;
           
    if (theHosts[lasttoken].kind == 'c' ||
        theHosts[lasttoken].kind == 'C' ||
        theHosts[lasttoken].kind == 'd' ||
        theHosts[lasttoken].kind == 'D'   )  
        h = 1;                      
   
        numOfSubnets = theHosts.size()+h;  //remember that template token in on the back  
    
    for (int i = 0; i<numOfSubnets; i++)
    {
         myBoxes.push_back(new SimpleBox(theHosts));
    }
       
}
Oh wait....I think I may understand you now.....

BoxMaker is getting called from the header file. By I don't specify the proper parameters in the header file for the BoxMaker class....(probably because I changed them after the original coding)...

This is what happens when you are trying to build onto something you already wrote....It has been troublesome.

So let me go try with this solution.....
thanks.
It is exactly as my example above.

Given the following class:

1
2
3
4
5
6
7
class Foo {
  private:
      std::string str;
      std::vector<int> vec;
  public:
      Foo( const char* s, size_t n, int v );
};


and the following implementation of the constructor:

1
2
3
4
5
6
7
8
Foo::Foo( const char* s, size_t n, int v ) 
    // The C++ standard guarantees you that by the time the first line of your constructor runs, all data
    // members have been fully constructed.  Because the compiler doesn't know any better, it attempts
    // to call the default constructor on all data members.  This results in a call to string's default constructor
    // (to initialize str) and to vector<>'s default constructor (to initialize vec) in that order.
{
    std::cout << str << std::endl;  // This will output nothing, since str is default constructed to the empty string.
}


Now consider this implementation:


1
2
3
4
5
6
Foo::Foo( const char* s, size_t n, int v ) 
   : str( s )  // str is now constructed using string::string( const char* ) constructor
   , vec( n, v ) // vec is now constructed using vector<int>::vector<int>( size_t n, int v = v() ) constructor
{
    std::cout << str << std::endl;  // This will output whatever the c-string pointed to by "s" was
}



Topic archived. No new replies allowed.