2

I have a class for sorting a char array. One of the constructors takes the parameter (size_t length). When I pass it a length of type int and try to compile, I get the error

driver.cpp:(.text+0x2c): undefined reference to 'Array::Array(unsigned long)'

Is there something obvious I am missing? What can I attempt to try to get this code to compile.

I have tried creating a variable of size_t but I get the same error. I have tried changing the parameter to an integer to see if had something to do with it being type size_t, but i get the same error but for int instead.

driver.cpp:(.text+0x2c): undefined reference to 'Array::Array(int)'

Array.h

class Array{
public:

  Array(size_t length);

  ...
  ...

}

Array.cpp

Array::Array (size_t length)
{
    std::cout << "garbage output" << std::endl;
}

main.cpp

int main (int argc, char * argv [])
{
  // TODO Add code here to test your Array class.

  Array ar1(10);

  return 0;
}

I expect the string "garbage output" but I receive a compilation error.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • As suggested in the accepted answer of the duplicate post, you have to compile both the source files to be able to generate the full binary containing all the linker symbols. i.e. `g++ Array.cpp main.cpp -o ArrayTest.out` – iammilind Sep 04 '19 at 02:17
  • 1
    Thanks a ton, sorry about the duplicate. – Jared Harmon Sep 04 '19 at 02:20
  • You should probably delete this question – Hemil Sep 04 '19 at 02:43
  • @Hemil, No; Duplicate questions need not be deleted. [Please refer this](https://meta.stackexchange.com/a/129845/163449). They offer another aspect to the same question and hence useful in searching from external sources. – iammilind Sep 04 '19 at 04:13

0 Answers0