External Struct being used in Class

Ok i'm trying to use structs and classes together in the code below to be executed in a class function, but im getting an errors like : No default constructor exists for class "ben". SO please look into these code snippets and tell how to address the situation properly.

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
  
struct ben
{
 int vt[2];
 ben( int a, int b);
};

//next is the class to be used with everyhing

class pp
{

//there is another struct called 'len' thats native to this class

struct len
{
 int tile;
}

len ln; // HERE EVERYTHING IS FINE SO FAR in the code but by time the next line below..
ben bn; // this line of code seems to be causing issues in a function definition later on in the tetr funtion below where its meant to be used.

void tetr( int , int );
};
#endif

//cpp file below containing 'tetr' function.

void pp::tetr(int aa, int bb)
{
 // Me attempting to implement pp class funtionality below

pp po;   // SIGN THAT SOMETHING IS WRONG BECOMES EVIDENT cuz this line of code is underlined in red under the 'po'.
// It's also saying :" the default constructor of pp cannot be referenced-- it is a deleted function"

....
.....
}
//Please could someone address whats going wrong and how it should be fixed?


Last edited on
A default constructor is a constructor that can be used to construct an object without passing any arguments. If you don't define any constructors the compiler will generate a default constructor for you. In the ben class you have defined a constructor that takes two ints as argument so the compiler will not generate a default constructor. If you want one you will either have to add it yourself, or you could ask the compiler to generate one for you by writing ben() = default; (note that the compiler generated default constructor will leave vt uninitialized which might not be what you want).
Last edited on
Topic archived. No new replies allowed.