# Function returning a structure - "no suitable constructor exists"

• 06-13-2012
Human
Function returning a structure - "no suitable constructor exists"
Hi guys,
it is my first post here (and first problem) and im just starting my journey with C programming, so please be kind to me :)

Here is my problem:
I am trying to have my function "Krzywa" returning a structure with array, but i get this "vect" at the end of function highlited with an error "no suitable constructor exists to convert from vector[4] to Vector".
Code:

```#include <stdio.h> #include <math.h> float siec [10][10]; float previous [10][10]; FILE *fp ; float fs; float u, t, x, theta; //predkosc, krok czasowy, dlugosc komorki, kat miedzy czyms a osia glowna float mi, Tmi, Tk; // float gamma, Teq, K, L; // cos, temp frontu, krzywizna, cieplo fazowe? float mi0, deltami, ms, dt; //mio, stale float siec [10][10]; float previous [10][10]; float dfsx, dfsy, n0x, n1x, n2x, n3x, n0y, n1y, n2y, n3y; float dolnaGranica, gornaGranica; struct Vector {     int x;     int y;     }; struct Vector vectors[4]; void zerowanie () {     int i, k;     for (i=0; i<10; ++i){         for (k=0; k<10; ++k){             siec[i][k]=0;         }     }     for (i=0; i<10; ++i){         for (k=0; k<10; ++k){             previous[i][k]=0;         }     } } struct Vector Krzywa (int i, int k) {     int n;     struct Vector vect[4];     for (n=0;n<4;n++){//jak znajduje faze stala w sasiedztwie, tworze krzywa K                     switch (n){                     case 0://1 wierzcholek                     dfsx=-previous[i][k-1]-previous[i+1][k-1]+previous[i][k]+previous[i+1][k];                     dfsy=-previous[i+1][k-1]-previous[i+1][k]+previous[i][k-1]+previous[i][k];                           vect[0].x = -dfsx/(sqrt(dfsx*dfsx+dfsx*dfsx));                           vect[0].y = -dfsy/(sqrt(dfsx*dfsx+dfsx*dfsx));                           //printf("%d %d",vectors[0].x,vectors[0].y);                           break;                         case 1:    //2 wierzcholek                           dfsx=-previous[i-1][k-1]-previous[i][k-1]+previous[i-1][k]+previous[i][k];                           dfsy=previous[i-1][k-1]+previous[i-1][k]-previous[i][k-1]-previous[i][k];                           if (dfsx==0 && dfsy==0)                           {                           vect[1].x =0;                           vect[1].y =0;                           }                           else {                           vect[1].x = -dfsx/(sqrt(dfsx*dfsx+dfsx*dfsx));                           vect[1].y = -dfsy/(sqrt(dfsx*dfsx+dfsx*dfsx));                           break;                           }                         case 2:    //3 wierzcholek                             dfsx=previous[i-1][k+1]+previous[i][k+1]-previous[i-1][k]-previous[i][k];                             dfsy=previous[i-1][k]+previous[i-1][k+1]-previous[i][k+1]-previous[i][k];                             if (dfsx==0 && dfsy==0)                             {                             vect[2].x =0;                             vect[2].y =0;                             }                             else {                             vect[2].x =-dfsx/(sqrt(dfsx*dfsx+dfsx*dfsx));                             vect[2].y =-dfsy/(sqrt(dfsx*dfsx+dfsx*dfsx));                             break;                             }                         case 3:        //4 wierzcholek                             dfsx=previous[i][k+1]+previous[i+1][k+1]-previous[i][k]-previous[i+1][k];                             dfsy=-previous[i+1][k]-previous[i+1][k+1]+previous[i][k+1]+previous[i][k];                             vect[3].x = -dfsx/(sqrt(dfsx*dfsx+dfsx*dfsx));                             vect[3].y = -dfsy/(sqrt(dfsx*dfsx+dfsx*dfsx));                             break;                         }                     }     return vect; }```
Any idea what it can mean? I omit the rest of the code with main function as the problem lays somewhere in here.
• 06-13-2012
laserlight
What is the exact error message? It should have a line number that can help in discovering the source of the error.

Furthermore, are you compiling as C or C++?
• 06-13-2012
Human

It's line number 96, with error as follows:

Code:

`Error        9        error C2440: 'return' : cannot convert from 'Vector [4]' to 'Vector'`
Im compiling it as C.
• 06-13-2012
laserlight
Oh, right. In Krzywa, vect is an array of 4 struct Vector objects. You declared Krzywa as returning one struct Vector object. Therefore, you must either return one struct Vector object, or allow an array of struct Vector objects to be passed to the function through a pointer to its first element.
• 06-13-2012
Human
Well, i did as u said, and it indeed helped :)
Thank you laserlight, cboard community may be proud to have you :)