guest7 0 Junior Poster

Hi,

I am getting the following error while compiling:

"Undefined symbols:
"main_class::binary(int, std::vector<int, std::allocator<int> >&, int)", referenced from:
main_class::identity(int, int, int)in test_sat.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [test] Error 1"

Following is the code :

int main_class::identity(int rowno, int size_row, int loop_iterate)
{
        /* Need to compute the universal set now */
        comb = pow(2,size_row)-1;
        int number, previous_count=51,fk=0;
        cout << "comb" << comb <<"\n" << endl;
        
       /* Intially the universal set is filled with 0's */
        for(int hfg=0; hfg<=comb; hfg++)
        {
                for(int ghj=0; ghj<size_row+1; ghj++)
                {
                        universal_row.push_back(0);
                }
                universal_column.push_back(universal_row);
                universal_row.clear();
        }

        /* We know the size of the universal set now in terms of rows = 0   to comb+1. Where the first row contains flip flops */

        for(int kl=0; kl<=comb; kl++)
        {
                number = kl;
                jml= (size_row);
                if(number < 0)
                        cout << "That is not a positive integer. \n";
                else
                {
                        binary(number,universal_column[kl],jml);
               }
       }
       return 0;
}

int binary(int number, vector<int> &ros1, int jmll)
{
        int remainder;
        if(number <= 1)
        {
                ros1[jmll] = number;
                jmll=jmll-1;
        }
        else
        {
                /* There is a right shift operator */
                remainder = number%2;
                ros1[jmll] = remainder;
                jmll=jmll-1;
                number = number >> 1;
                binary(number,ros1,jmll);
        }
        return 0;
}

I do not sure why i am getting the error.

Thanks

Dani AI

Generated

— The linker message means the program expects a member function named binary inside main_class but no matching definition was found at link time. That usually happens when you declare a method in the class (in the header) but define it outside the class without qualifying it with the class name. To resolve it you can either make binary a true member by defining it with the class qualifier, or remove the member declaration and keep it as a free function.

Here is the minimal pattern you need for an out‑of‑class member definition:

int main_class::binary(int number, std::vector<int>& ros1, int jmll)
{
    // implementation...
}

Make sure the declaration and the definition match exactly: same parameter types (including std::vector vs vector and reference/const qualifiers), same namespace, and same static/const modifiers if any. Also ensure the .cpp file that contains that definition is being compiled and linked (clean the build and re-run your make).

If you still see the error after that, post the class header (main_class declaration) and your Makefile snippet — that will let people confirm whether the symbol name/signature mismatches or a translation unit is simply not being linked. For reference on out‑of‑class member definitions see Member functions on cppreference and the C++ classes tutorial at cplusplus.com.

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.