mardi 21 septembre 2021

Undefined reference to constructor problem

See the below-given code

#include <iostream>
using namespace std;

class Number
{
    int a;

public:
    Number();

    Number(int num_1) {
        a = num_1;
    }

    void print_number(void) { cout << "Value of a is " << a << endl; }
};

int main()
{
    Number num_1(33), num_3;
    Number num_2(num_1);

    num_2.print_number();
    return 0;
}

In the above code, I am having 2 constructors in the same class but when compiling it,gives me the error

ccnd0o9C.o:xx.cpp:(.text+0x30): undefined reference to `Number::Number()'
collect2.exe: error: ld returned 1 exit status  

Can anyone solve this problem? and I still need the 2 constructors but without replacing num_3 with num_3() the main function.

Aucun commentaire:

Enregistrer un commentaire