473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Class hierachy and methods

Hello,

I am working on a project and have become a little confused on how to
call methods from another class. Before I explain, here is an example:
class 0
{
main()
{
class 1 = new class1();
}
}

class 1
{
class1()
{
/*
now I want to call a method from class 0 (i.e.
class0.getVariable()) do I need to make a new instance or what since
this class already being called by class 0?
*/
}

}
Any idea? Also, class0 is a windows form and class1 is not, so calling
it again doesnt really make sense to me...

Thank you!

Tom

Aug 20 '06 #1
3 1259
Tom Machado wrote:
I am working on a project and have become a little confused on how to
call methods from another class. Before I explain, here is an example:
class 0
{
main()
{
class 1 = new class1();
}
}

class 1
{
class1()
{
/*
now I want to call a method from class 0 (i.e.
class0.getVariable()) do I need to make a new instance or what since
this class already being called by class 0?
*/
}

}

Any idea? Also, class0 is a windows form and class1 is not, so calling
it again doesnt really make sense to me...
The second class need a reference to the first class.

If the first class A do:

B o = new B(this);

and the second class B looks like:

public class B
{
private A a;
public B(A a)
{
this.a = a;
}
...
}

then other metods in B can call:

a.somemethod();

Arne
Aug 20 '06 #2
You can pass a reference to class0 to the constructor of class1, then
call class0 functions through the reference object.

class 1 = new class1(this);

T

Tom Machado wrote:
>Hello,

I am working on a project and have become a little confused on how to
call methods from another class. Before I explain, here is an example:
class 0
{
main()
{
class 1 = new class1();
}
}

class 1
{
class1()
{
/*
now I want to call a method from class 0 (i.e.
class0.getVariable()) do I need to make a new instance or what since
this class already being called by class 0?
*/
}

}
Any idea? Also, class0 is a windows form and class1 is not, so calling
it again doesnt really make sense to me...

Thank you!

Tom
Aug 20 '06 #3
Perfect! Thank you for your help!

Aug 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Dave | last post by:
Hi I'm making a 3D Engine which consists of the class C3DEngine. Part of this engine is a file loader, a class called CMeshLoader. I have made an instance of CMeshLoader in C3DEngine, ie...
24
by: Brad Marts | last post by:
I would like to have a function that takes as an argument a base class but performs differently depending on which type of derived class is passed. Can I tell which derived class is passed? For...
9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
1
by: mschellens | last post by:
Does a c++ compiler use late or early binding for member calls of the last class in a hierachy when invoked through a pointer of this classes type? Thanks, marc class A { public: virtual...
2
by: A. Elamiri | last post by:
Hello, I have a list of product categories and each category may or may not have children and it goes down in a varying level of depth. Now I have to pull this category information for...
6
by: Baris | last post by:
Given the C# code below, can anyone think of a better class design? What really gets my goat is that the code within derived classes D1 and D2 is identical and in my mind should be refactored into...
4
by: Hei | last post by:
Hi is vb.net' "interface" is sound like C++ "abstract class" ? Hei
3
by: John Henry | last post by:
Hi list, I am trying to understand better Python packaging. This might be a messed up class hierachy but how would I break this cyclic relatioship? In file A: from B import B_Class ...
10
by: areeba | last post by:
Hi! Can you please help me in making correct object hierachy of the following animals, Tiger, lion, cat, wolf, hyena, wild dog, not-so-wild dog and pet dog. Also should put any...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.