no match for call to

hello!

i have a class with default constructor and another constructor :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Row
{
    public:
        int flows_len;                  
        string **flows; 
        int Num_flows;                  
        
        Row (int num){                    // Class Constructor
        flows_len = num+1;
        flows = new string *[flows_len];
        for (int i=0;i<flows_len;i++){
        flows[i] = new string[47];}
        Num_flows=0;
        };
        
        Row (){};


in my main(), i declare an array of these objects :

1
2
  Row *flows_table_hour;
  flows_table_hour=new Row[12];


but later on, when i want to initialize an object of the array:
1
2
int Number=24;
flows_table_hour[nfcapd](Number/2);


i get this error :main.cpp:172:37: error: no match for call to ‘(CVSRow) (int)’

i dont know how to make this initialization.

thanks a lot!!
You should do it like this:
 
flows_table_hour[ nfcapd ] = Row( Number / 2 );
An object cannot be constructed multiple times. Once it is default constructed, it cannot be reconstructed:

1
2
3
flows_table_hour=new Row[12];  // <- they are being constructed here

flows_table_hour[nfcapd](Number/2); // <- so you cannot reconstruct them here 


What that 2nd line is actually doing is trying to call the parenthesis operator on your existing objects... which if you didn't overload the parenthesis operator, would give you an error like the one you are seeing.



The closest thing you can do to what you want is to construct a new object, then assign it to the old object:

1
2
3
flows_table_hour=new Row[12];  // <- construct these as you are

flows_table_hour[nfcapd] = Row(Number/2); // <- then assign these to a newly constructed object 


However this approach requires the objects be assignable, which means you'll have to overload the assignment operator. You'll probably want to overload the copy constructor, too. And the destructor, if you haven't already.


Also note that your class is going to be error prone as it is now. I highly recommend avoiding direct dynamic allocation (get rid of the new[] calls) and use a container like vector or something. Currently, your default constructor is not initializing the 'flows' member, so when your destructor tries to delete it (which I'm assuming it does)... it will try to delete some random pointer, which will cause your program to crash.


EDIT:

Just to clarify... if you simply do the example code change above and nothing else it will cause your program to crash or at least leak memory. You need to overload at least the assignment operator to make this work properly. Or you need to use a container instead of new[].
Last edited on
You are trying to call a constructor on an object that has already been created. You've declared a default constructor that takes no parameters. This is what the compiler used to build your object. Instead of a constructor, try making the call some sort of function with an int as a parameter.

edit:
I'm wondering, couldn't you do this:
1
2
3
4
5
  Row *flows_table_hour;
  flows_table_hour=new Row(12);

int Number=24;
flows_table_hour[nfcapd](Number/2);


flows_table_hour=new Row(12); sets aside memory, but doesn't actually create the object.



Last edited on
You need to overload at least the assignment operator to make this work properly


so its : operator = (Row& row, ???) i'm a complete beginner... i dont know this stuff!!! could you help me??
You could use vectors and save yourself the trouble. That class doesn't look like it needs a default constructor anyhow.
Topic archived. No new replies allowed.