As above I have two classes : abstract Stack and class Function, with
Function holding one instance of Stack. Now, when calling constructor for
Function I would also to call it for Stack. The problem is I got :
unresolved symbol error: Stack(). What should I do ? Both files Stack.java
and Function.java are in project.
pseudocode :
abstract Function{
Stack S;
Function(){
S = Stack();
}
}
rossum - 29 Jul 2007 19:57 GMT
>As above I have two classes : abstract Stack and class Function, with
>Function holding one instance of Stack. Now, when calling constructor for
[quoted text clipped - 11 lines]
>
>}
When you call any constructor, you need the "new" construction:
S = new Stack();
This will not compile in your particular case because you have
declared your Stack class to be abstract. Abstract classes cannot be
instantiated, and the compiler will tell you so.
One way to initialise the stack member variable in Function is to
initialise it from a constructor parameter:
public Function(Stack ss) {
S = ss;
}
This will compile.
Inside your program you could derive a non-abstract class from your
abstract Stack and you can pass an instance of that derived class into
your Function constructor:
class ConcreteStack extends Stack { ... }
ConcreteStack myCStack = new ConcreteStack();
Function myFunction = new Function(myCStack);
rossum
Thomas - 29 Jul 2007 20:10 GMT
> >As above I have two classes : abstract Stack and class Function, with
> >Function holding one instance of Stack. Now, when calling constructor for
[quoted text clipped - 40 lines]
>
> rossum
Thx, I'm just to tired.
Roedy Green - 29 Jul 2007 21:36 GMT
>pseudocode :
>abstract Function{
[quoted text clipped - 5 lines]
>
>}
Please post real code. This is too far from real code. Please have a
look at http://mindprod.com/jgloss/codingconventions.html
What I think your question might be is this:
I have a circular reference:
class F {
Stack s;
...
}
class Stack{
F f ;
...
}
If I compile F first javac can't find Stack. If I compile Stack
first, it can't find F. I'm hosed. What do I do?
The answer is at http://mindprod.com/jgloss/javacexe.html#CIRCULAR

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com