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

Dynamic Allocation of 2D array of <class>

I have switched to a new compiler (gcc/g++ 3.2 on rh linux 8.0) and I
cannot seem to dynamically allocate two dimentonal arrays (or even
singel dimetional arrays!) of any user defined classes.

Here is a simple example of an array of user defined class that *used*
to work, but doesn't anymore:
-------------------begin code-----------------------
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

class Pixel
{
public:
Pixel();

int i;
int j;
};

int main()
{
Pixel p[4];

for (int i=0;i<4;i++)
{
p[i].i=i;
p[i].j=i*i;
}

for (int i=0;i<4;i++)
{
cout<<p[i].i<< " "<<p[i].j<<endl;
}
return 0;
}
----------------------end code------------------

Here is the error message I get when I compile:

[root@voyager hw5]# g++ -o dblarray dblarray.cpp
/tmp/ccMX0JlL.o: In function `main':
/tmp/ccMX0JlL.o(.text+0x30): undefined reference to
`Pixel::Pixel[in-charge]()'
collect2: ld returned 1 exit status
[root@voyager hw5]#

I get the same error if I try to allocate pointers of pointers etc...

Any idea what I'm missing?

--Dave

Jul 19 '05 #1
2 6467
On Fri, 10 Oct 2003 23:04:11 GMT, lestat <le****@student.umass.edu> wrote:
I have switched to a new compiler (gcc/g++ 3.2 on rh linux 8.0) and I
cannot seem to dynamically allocate two dimentonal arrays (or even
singel dimetional arrays!) of any user defined classes.

Here is a simple example of an array of user defined class that *used*
to work, but doesn't anymore:
-------------------begin code-----------------------
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

class Pixel
{
public:
Pixel();

int i;
int j;
};

int main()
{
Pixel p[4];

for (int i=0;i<4;i++)
{
p[i].i=i;
p[i].j=i*i;
}

for (int i=0;i<4;i++)
{
cout<<p[i].i<< " "<<p[i].j<<endl;
}
return 0;
}
----------------------end code------------------

Here is the error message I get when I compile:

[root@voyager hw5]# g++ -o dblarray dblarray.cpp
/tmp/ccMX0JlL.o: In function `main':
/tmp/ccMX0JlL.o(.text+0x30): undefined reference to
`Pixel::Pixel[in-charge]()'
collect2: ld returned 1 exit status
[root@voyager hw5]#

I get the same error if I try to allocate pointers of pointers etc...

Any idea what I'm missing?


You've declared a default constructor but never defined it.

Jul 19 '05 #2
Alf P. Steinbach wrote:
On Fri, 10 Oct 2003 23:04:11 GMT, lestat <le****@student.umass.edu> wrote:

I have switched to a new compiler (gcc/g++ 3.2 on rh linux 8.0) and I
cannot seem to dynamically allocate two dimentonal arrays (or even
[snip]
Any idea what I'm missing?

You've declared a default constructor but never defined it.


Well that was easy. Thank you very much, I've been stuck on this for hours!

Jul 19 '05 #3

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

Similar topics

0
by: Dan Trowbridge | last post by:
He everyone, I just getting started with .NET and I am having a porting problem. I get and error in code that lookes like this (really stripped down but you get the idea)... class dt {...
7
by: Dan Trowbridge | last post by:
He everyone, I am just getting started with .NET and I am having a porting problem. I get and error in code that lookssomething like this (really stripped down but you get the idea)... class...
11
by: Wolfgang Kaml | last post by:
I am not sure if this is more of an expert question, but I am sure that they are out there. I'd like to setup a general application or bin directory on my Win2003.Net Server that will hold some...
4
by: Gary li | last post by:
Hi, all I find "template template" class cann't been compiled in VC6 but can ok in Redhat9. I write a test program like as: template< template<class> class T> class A { }; int main() {...
1
by: Birthe Gebhardt | last post by:
Dear all, I could not find the way to handle 'not normal' list objects, for example using remove_if, find etc. Example : class Todo { public : .. int getNumber(){ return num_;}
10
by: jason.cipriani | last post by:
Is there any difference between declaring a template parameter as a "typename" or a "class"? E.g. template <class TT f() { } template <typename TT g() { } Thanks, Jason
2
by: =?Utf-8?B?Unlhbg==?= | last post by:
Hi, How can I get around runtime error that says I can not explicit cast List<SubClassto ICollection<Class>? Generic List inhertis generic ICollection and Subclass inherits Class, then...
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: 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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
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.