473,403 Members | 2,354 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,403 software developers and data experts.

class - array - initialize in constructor

Hi!!
I want to use an array into a function of an object.I decided to declare the array in the class and to initialize its values with the constructor.I wrote something like this:
Expand|Select|Wrap|Line Numbers
  1. class my_class{
  2.         public:
  3.                  ....... 
  4.                  int my_array[15];
  5.                  ......
  6.        }
  7. my_class::my_class()
  8. {
  9.             my_array{0,1,2,3....,14};
  10.                  }
  11.  
but the compiler found some problems.How i can do this?how i can call the array when i am in a function of the class? Any help and ideas are acceptable

Maradona
=======
Dec 22 '06 #1
1 2746
Banfa
9,065 Expert Mod 8TB
You can't iitialise an array like this, you have to do it something like

Expand|Select|Wrap|Line Numbers
  1. my_class::my_class()
  2. {
  3.     my_array[0] = 0;
  4.     my_array[1] = 1;
  5.     my_array[2] = 2;
  6.     my_array[3] = 3;
  7.     ...
  8.     my_array[14] = 14;
  9. }
  10.  
Of course in this case you could always use a loop to reduce the number of code lines.
Dec 24 '06 #2

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

Similar topics

106
by: A | last post by:
Hi, I have always been taught to use an inialization list for initialising data members of a class. I realize that initialsizing primitives and pointers use an inialization list is exactly the...
13
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes....
17
by: Mark | last post by:
uhhmmm... not really sure how to word this. i cant get get this to compile.. i'm not sure what the proper syntax to do this is.. hopefully it's self explanatory. here's my class: ------ class...
16
by: Allen | last post by:
I have a class that returns an arraylist. How do I fill a list box from what is returned? It returns customers which is a arraylist but I cant seem to get the stuff to fill a list box. I just...
12
by: jimmij | last post by:
Hi, Please look at the code bellow /*******************/ class ctab { private: static const unsigned n=48;
5
by: partha.p.das | last post by:
Here is my class: class MyClass { public: MyClass(); ~MyClass(); private:
7
by: Ole Nielsby | last post by:
I want to create a class with a variably-sized array inlined. The array size will be known at each instantiation but not at compile time. Once created, arrays won't grow or shrink and their...
17
by: Jef Driesen | last post by:
Suppose I have a datastructure (actually it's a graph) with one template parameter (the property P for each edge and vertex): struct graph<P>; struct vertex<P>; struct edge<P>; I also have...
2
by: Howard | last post by:
Hi, I've got a program whose main object contains an array of "cells", each of which contains an array of "sub-cells", each of which contains an array of "sub-sub-cells". The cells, subcells...
8
by: Malciah | last post by:
I posted this on another site, but so far I've had no answers. So, I decided to try it here. -------------------------------------------------------- I've been learning C++ for about 6 weeks now,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.