• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

What is an undefined reference ?

Hello,

I'm working on a program where I have several classes inheriting from a sort of mother-class.

One is a binary search tree, and another one is a stack. I have a function (a member function of the search tree) that uses the stack . . which uses nodes from the search tree. . . . like so :

class Tree {}
class Stack : public Tree {}

void afunction
{
        // s is a stack, p is a pointer to a  node in the tree
         . . .
         s.push(p);
}

I have an error "  [Linker error] undefined reference to `Stack::push(node*)'  "

My question is this . . what's a linker error ? For that, what is an undefined reference ? ( Especially in relation to this particular error . . )

0
princess_of_reason
Asked:
princess_of_reason
  • 4
  • 2
1 Solution
 
AxterCommented:
Hi princess_of_reason,
> >I have an error "  [Linker error] undefined reference to `Stack::push(node*)'  "

Your class does not have a push member function.


Cheers!
0
 
AxterCommented:
From what you've posted, the Stack class doe not have a push member function, so you can't call s.push

If you need that functionallity, you need to add the push method to your class.
0
 
AxterCommented:
princess_of_reason,
> >what's a linker error ? For that, what is an undefined reference ? (
> >Especially in relation to this particular error . . )

You usally get this type of linker error when you have declared a method, but you have not defined it.

class foo
{
  int ImNotImplemented();
  int ImImplemented()
  {
     return 0;
  }
};

foo myfoo;
myfoo.ImNotImplemented();//Will cause linker error
myfoo.ImImplemented();//This is OK
myfoo.NoSuchFunction();//Will cause compile error

If you declare a method, but don't have implementation code, that will usually cause a linker error.
If you don't declare it at all, then you'll get a compile error.

You need both implementation and declaration.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
princess_of_reasonAuthor Commented:
Err .. altogether my code ended up being really long and messy, so I posted "   . . . .  "  instead. My stack does have the push function, and half a dozen other things. . . lol.

I'm sorry for the confusion . . . I'm just trying to figure out what the error means.

So I guess somehow it's not finding push ? Hmm . .
0
 
AxterCommented:
>>So I guess somehow it's not finding push ? Hmm . .

You may have a push method, but it may not have the correct argument type that the linker is looking for.

Since p is a pointer to a node, your push method needs to take that exact type of argument, and it needs to be implemented.

If you post your class declaration, and the implementation for push, we could point exactly where the problems at.
0
 
princess_of_reasonAuthor Commented:
Thank you, that answers my question. :)

I'd rather figure out what's wrong exactly myself, as this program is a homework assignment. I just needed to know what those terms meant. :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now