473,387 Members | 1,530 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 Constructors

ilikepython
844 Expert 512MB
Hi I have a question about classes. If you have a class and its constructor takes arguements. Is there a way you can create an array that stores objects from that class but each one of them getting diefferent arguements?

Btw, I'm using it to create a game using SDL, tetris and I have a class fo blocks and for the pieces and I want the pieces class to have an array that stores the blocks in its piece.

Thanks in advance.
Apr 12 '07 #1
8 1582
Banfa
9,065 Expert Mod 8TB
No if you create an array of classes either as automatic variables or by allocating then they all call the default constructor.
Apr 12 '07 #2
ilikepython
844 Expert 512MB
No if you create an array of classes either as automatic variables or by allocating then they all call the default constructor.
So you're saying that if I create an array of instances they all have to be passed the same arguments?
Apr 12 '07 #3
Banfa
9,065 Expert Mod 8TB
So you're saying that if I create an array of instances they all have to be passed the same arguments?
No I am saying you can't pass any arguments, you have to use the default constructor, that is a constructor that takes no arguments or where all arguments have a default value.

The workaround for your problem is to have a default constructor tat does very little and then to have an Initialise member function that takes the arguments and initialises the class data from them. Then you construct your array and then call the initialise member function for each array item.
Apr 12 '07 #4
ilikepython
844 Expert 512MB
No I am saying you can't pass any arguments, you have to use the default constructor, that is a constructor that takes no arguments or where all arguments have a default value.

The workaround for your problem is to have a default constructor tat does very little and then to have an Initialise member function that takes the arguments and initialises the class data from them. Then you construct your array and then call the initialise member function for each array item.
Oh ok then thanks very much.
Apr 12 '07 #5
Hey Python I'm looking for my post on classes and ran across yours. Looks like your a term ahead of me, are you a GSP major? I have a post here somewhere and it deals with classes and constructors, having written our first program using structs now we're into classes, seemingly quick too. Joe..

Good luck, sounds confusing.
Aug 13 '07 #6
What do you do when you've forgotten what you named your thread and you can't find it? i'd appreciate it

<snipped>
Aug 13 '07 #7
ilikepython
844 Expert 512MB
Hey Python I'm looking for my post on classes and ran across yours. Looks like your a term ahead of me, are you a GSP major? I have a post here somewhere and it deals with classes and constructors, having written our first program using structs now we're into classes, seemingly quick too. Joe..

Good luck, sounds confusing.
Well, I''m not in college and I have no idea what a GSP major is. I didn't learn this with school, I just did it on my own.
Aug 13 '07 #8
ilikepython
844 Expert 512MB
What do you do when you've forgotten what you named your thread and you can't find it? i'd appreciate it

<snipped>
You go to your profile and click on "find all threads started by joeschnell" and it will take you to a list of threads you made.

Also, please don't post your email, it's against the posting guidelines.
Aug 13 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
23
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
6
by: Fred | last post by:
Hi I have a class defined in a library that I'd like to add some extra functionality to. This will involve adding a few member variables and a few related methods. As I understand it I can...
7
by: Hyoung Lee | last post by:
A simple method of simulating a class, such as C++ or UML class, in C would be using the struct construct. Similarly, we use C functions to simulate a methods; e.g., rv method_a (&struct,...
3
by: J.J. Feminella | last post by:
(Please disregard the previous message; I accidentally sent it before it was completed.) I have source code similar to the following. public class Vehicle { protected string dataV; // ......
3
by: craigkenisston | last post by:
Hi, I have a class with 3 constructors, one takes no arguments, other take an string and other an xml document. I want to derive another class of it, I don't need a different constructor so I...
9
by: Jim Starcher | last post by:
I cannot get the intellisense hints to work on my class constructors. Would you please tell me what I am doing wrong? public class MyObject { //Constructors /// <summary> /// Used to...
1
by: John | last post by:
Hi, Maybe someone can help me with the following: "The first task by any derived class constructor is to call it’s direct or indirect base class constructor implicitly or explicitly", reads the...
2
by: TEK | last post by:
Hello We're having a issue with a part of our app that is very strange, and I'm unable to see that it should be possible. We have: A collection (ActivityCollection) that is inherited from a...
6
by: Peng Yu | last post by:
Hi, I want B has all the constructors that A has. Obviously, the code below would not work. I could define a corresponding B's constructor for each A's constructor. But if A has many...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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.