Strings as arguments (Undefined reference)

Can anyone tell me what would be causing the following error:

C:\AppData\Local\Temp\cc4arLND.o(.text+0x543):list.cc: undefined ref
erence to `list::fixSize(basic_string<char, string_char_traits<char>, __default_
alloc_template<0, 0> > &, int)'
collect2: ld returned 1 exit status

With the following function.

1
2
3
4
string fixSize(string in, int len)
{ 
return in; //empty function for now
}


Called in the following way:

1
2
string temp = "Test";
temp = fixSize(temp, 20);
Last edited on
Can you provide more code? The compiler thinks you are trying to call a method in some list class.
Your prototype doesn't match your function body.

Your prototype probably looks something like this:

 
string fixSize(string& in, int len);


And it's part of a 'list' class?

So your function body should look like this:

1
2
3
4
5
6
7
8
string list::fixSize(string& in, int len)
//      ^                  ^
//      |                  |
//      |                  note the &, same as your prototype
//     class and scope operator (::)
{
  return in;
}


EDIT: doh, Duoas is faster than me!
Last edited on
Thanks guys, forgot to specify it as part of list.
Topic archived. No new replies allowed.