i keep getting these errors with my program and i was wondering if anyone can help.

/tmp/cc2Rxau2.o: In function `main':
prac.cpp:(.text+0x101): undefined reference to `Barcode::Barcode()'
collect2: ld returned 1 exit status

Code:

#include <iostream>

using namespace std;

class Barcode
{

public:
        Barcode(int zipcode);

        Barcode(char bar);

        Barcode();

        int convert(int num);



private:




        int return_bar();

        int return_zip();

};


int main()
{
        int choice;
        int usrzip;
        Barcode zip;
        cout << "enter 1 if you want to change a zipcode to barcode, or a 2 for a barcode to zipcode." << endl;


        cin >> choice;


        if(choice == 1)
 {
                cout << "enter your 5 digit zipcode." << endl;
                cin >> usrzip;

                int num1, num2, num3, num4, num5;
                int temp1, temp2, temp3, temp4;
                int bar_num1, bar_num2, bar_num3, bar_num4, bar_num5;

                num1 = usrzip % 10;
                temp1 = usrzip / 10;
                num2 = temp1 % 10;
                temp2 = temp1 / 10;
                num3 = temp2 % 10;
                temp3 = temp2 / 10;
                num4 = temp3 % 10;
                temp4 = temp3 / 10;
                num5 = temp4 % 10;


        cout << num5 << " " << num4 << " " << num3 << " " << num2 << " " << num1 << endl;              

                bar_num1 = zip.convert(num1);
                bar_num2 = zip.convert(num2);
                bar_num3 = zip.convert(num3);
                bar_num4 = zip.convert(num4);
                bar_num5 = zip.convert(num5);

        cout << bar_num5 << bar_num4 << bar_num3 << bar_num2 << bar_num1 << endl;

        }

}

int Barcode :: convert(int num)
{
        char result;
                switch(num)
        {
                case 1:
                        result = 00011;
                        break;
                case 2:
 result = 00101;
                        break;
                case 3:
                        result = 00110;
                        break;
                case 4:
                        result = 01001;
                        break;
                case 5:
                        result = 01010;
                        break;
                case 6:
                        result = 01010;
                        break;
                case 7:
                        result = 10001;
                        break;
                case 8:
                        result = 10010;
                        break;
                case 9:
                        result = 10001;
                        break;
                default:
                        cout << "not valid choice." << endl;
        }


}

Recommended Answers

All 3 Replies

You have declared three different constructors for Barcode: Barcode(int zipcode); Barcode(char bar); and Barcode() If you declare any other constructors and then a default one, you must define that default constructor (in fact in your file you don't have _any_ of them defined).

could you help me with how to define the constructors and how i to use them in my program.

Barcode::Barcode(int zipcode)
{
          take in zipcode, convert it (with the built in function )and assign to internal barcode value

}

Barcode::Barcode(char Bar)
{
set internal barcode to value passed in


}

Barcode::Barcode()
{
     do nothing or establish defaults (ex. barcode = 00000 or zipcode = 00000  

}

Since you have no private variables to assign any of these to, you need to make some. Check on what your text has to say about them.

These c'tor definitions would go before your Barcode::convert() definition.

Looking back, probably your best bet in main would be to not use your convert function statically but to create individual barcode objects.

Skim over your text on instantiating objects out of your classes. In summary, you probably need an overhaul but it shouldn't be too involved.

P.S. I'm not trying to cast you off or anything, far from it, I just think you should rethink the requirements a bit more. You have a couple of good functions with your class, but what is the most effective way to use them so your code is object oriented. You want your objects to be initially given a barcode or be given a zipcode to convert to a barcode. How can you store all of that content into that one piece of information.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.