?
Solved

What is an undefined reference ?

Posted on 2005-03-03
6
Medium Priority
?
303 Views
Last Modified: 2010-04-01
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
Comment
Question by:princess_of_reason
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 13452269
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
 
LVL 30

Expert Comment

by:Axter
ID: 13452280
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
 
LVL 30

Expert Comment

by:Axter
ID: 13452304
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:princess_of_reason
ID: 13453822
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
 
LVL 30

Accepted Solution

by:
Axter earned 2000 total points
ID: 13453845
>>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
 

Author Comment

by:princess_of_reason
ID: 13469445
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question