-1

I am not sure why I am getting this error. The function should return true or false. All variables have been defined and the error I get is:

/tmp/ccTspEHr.o: In function `main':
rectangles.cpp:(.text+0x169): undefined reference to `rectangle_name(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<Rectangle, std::allocator<Rectangle> >)'
rectangles.cpp:(.text+0x310): undefined reference to `rectangle_name(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<Rectangle, std::allocator<Rectangle> >)'
rectangles.cpp:(.text+0x7b0): undefined reference to `rectangle_name(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<Rectangle, std::allocator<Rectangle> >)'
collect2: ld returned 1 exit status

Function prototype:

bool rectangle_name(string prompt, string invalid, string used, string n, vector<Rectangle> rectangle);

function definition:

bool rectangle_name(string prompt, string invalid, string used, string & n, vector<Rectangle> rectangle)
//This function reads in a prompt and reads in the name of the rectangle or stop\

{
  cout << prompt;
  getline (cin, n);
  // do other stuff and return true or false
}

What causes these errors?

Varaquilex
  • 3,447
  • 7
  • 40
  • 60
user3058698
  • 11
  • 1
  • 1
  • 2
    Double check your signature vs. the definition. They don't match (`n` parameter). – crashmstr Dec 02 '13 at 19:38
  • When posting questions about errors, please post the error with the question, complete and unedited. Please edit your question to include the errors. Also please show the declaration of the variables involved. – Some programmer dude Dec 02 '13 at 19:38
  • 1
    Please edit your code to be a [Short, Self Contained, Correct Example](http://sscce.org/). – Varaquilex Dec 02 '13 at 19:39
  • @JoachimPileborg sorry, added the error, and I did not show the declarations because I thought the code was too long. – user3058698 Dec 02 '13 at 19:43
  • 1
    This was asked **literally half an hour ago.** I cannot possibly imagine the amount of research you put in this question. –  Dec 02 '13 at 19:43
  • Actually I've been working on this since last night and all of the errors I've seen involved reading in a file, which is not what I am trying to do. This is why I posted the question. Their answers were not relevant to mine. @H2CO3 – user3058698 Dec 02 '13 at 19:47

2 Answers2

3

You declared

bool rectangle_name(string prompt, string invalid, string used, string n, vector<Rectangle> rectangle);
                                                                 ^^^^^^^

and defined

bool rectangle_name(string prompt, string invalid, string used, string & n, vector<Rectangle> rectangle)
                                                                 ^^^^^^^

See the fourth parameter? Declaration string n, and definition string & n. They don't match. Make those two match and the error will be gone.

Varaquilex
  • 3,447
  • 7
  • 40
  • 60
2

It is very simple. You should define the function. You declared the function as

bool rectangle_name(string prompt, string invalid, string used, string n, vector<Rectangle> rectangle);

but defined another function

bool rectangle_name(string prompt, string invalid, string used, string & n, vector<Rectangle> rectangle)

Notice the declaration of the parameter with name 'n'.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335