473,386 Members | 1,790 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,386 software developers and data experts.

Storing Objects in Objects

I'm new at working with object oriented programming. Here's what I want to
do.

Create three objects of the same class, A, B and C. These will live the
life of the program. I want to be able to store A in B, by referrence or
otherwise, and then retrieve A at a later point.

I can create the class and then create a new object, but I can't store A in
B, and forget about retrieving A.

Could you post a brief example?
Jul 21 '05 #1
2 1116
In C# you can do something like this.

I would recommend C# over VB.NET for learning object-oriented programming since the syntax is simpler.

Not exactly sure just what you're trying to accomplish. You might want to look into using container classes.

namespace N
{
public class CLASS
{
public CLASS c;
}

[STAThread]
static public void Main()
{
CLASS A, B, C;

B = new CLASS();
B.c = new CLASS();
C = new CLASS();
}
}
"Jim Bayers" wrote:
I'm new at working with object oriented programming. Here's what I want to
do.

Create three objects of the same class, A, B and C. These will live the
life of the program. I want to be able to store A in B, by referrence or
otherwise, and then retrieve A at a later point.

I can create the class and then create a new object, but I can't store A in
B, and forget about retrieving A.

Could you post a brief example?

Jul 21 '05 #2
Hi Jim,

You mean such a simple approach as this?
Public Module Main
Public Sub Main()
Dim A As New ABC
Dim B As New ABC
Dim C As New ABC
A.val = "0"
B.val = A
C.val = B
A.val = "2"
MessageBox.Show(DirectCast(DirectCast(DirectCast(C , ABC).val,
ABC).val,ABC).val.ToString)
End Sub
Public Class ABC
Public val As Object
End Class
End Module

The result of this is 2.

I hope this gives an idea?

Cor


Jul 21 '05 #3

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

Similar topics

6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
12
by: Alfonso Morra | last post by:
I have the ff code for testing the concept of storing objects: #include <vector> #include <iostream> using namespace std ; class MyClass { public: MyClass(){
10
by: Diego F. | last post by:
Hello. I need to store custom objects in a SQL Server 2000 table. Which is the easiest way to do it? Do I need to write methods to store each attribute separately from C# app to the table and the...
4
by: Frank Rizzo | last post by:
In classic ASP, it was considered a bad idea to store VB6-created objects in the Application variable for various threading issues. What's the current wisdom on storing objects in the Application...
2
by: jakk | last post by:
Below is the exception that Iam getting. It says that the DataView that Iam storing in the session is not Serializable. BUt works fine if I store in the inproc session and fails if I switch to...
7
by: C G | last post by:
Dear All, What's the best way to store jpgs in postgresql to use in a web page? I tried to use large objects, but how would you extract them from a table to be viewed in a web-page without...
9
by: david | last post by:
I have a class with some business-logic and with every roundtrip, I need an instance of this class, so I have to create it, every time again. That doesn't seem very efficient. I thought it would...
11
by: toton | last post by:
Hi, all of the containers in STL stores object itself (thus copy contsructability & assignability is needed), while NTL or boost ptr_container stores pointer to the object in the container (either...
3
by: RSH | last post by:
Hi, I have a situation where I have created an object that contains fields,properties and functions. After creating the object I attempted to assign it to a session variable so i could retrieve...
10
by: nayden | last post by:
I started playing with python a few weeks ago after a number of years of perl programming and I can say that my first impression is, unsurprisingly, quite positive. ;) The reason I am writing here...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.