Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-05-2007, 06:36 PM   #1 (permalink)
moramoga
Recruit
 
Join Date: Feb 2007
Posts: 2
moramoga is on a distinguished road
help with arraylist

I need to make an arrayList in my main, the user gives the size, and I am inserting airplane objects, but the compiler keeps throwing me an exception: no appropriate default constructor available

Here is my code:

Airplane* myAirplanes= NULL;

cout << "Size of the arraylist: " << endl;
cin >> cant;
cant = cant-1;
exception-----> aviones = new Avion[cant];
moramoga is offline   Reply With Quote
Old 02-05-2007, 11:46 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
What is Avion? A struct? A class? Your mothers birthdaypressent ?
The compiler claims to be in need of a constructor for the class, and since you didn't show what it is, I'm assuming you need just that ie:
Code:
class Avion{
  private:
    // something hush hush
  public:
    Avion(void) {};   // this is a default constructor for class Avion
                      // Usualy called when using new()
    ~Avion(void) {};  // this is a default destructor for class Avion
                      // Usualy called when using delete()
    ...
};
I belive the default constructor/destructor is described in just about any C++ book describing how to use classes.
But since you didn't provide more than a few lines of code, I could be telling you something which you allready know and are using, and as a result this is just pissing you of.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 02-06-2007, 08:45 AM   #3 (permalink)
moramoga
Recruit
 
Join Date: Feb 2007
Posts: 2
moramoga is on a distinguished road
That solved my first exception, now I have another one when I do this:

actualAirplane= new Airplane();
(arrayList--->)airplanes[0] = actualAirplane;

no operator defined which takes a right-hand operand of type 'class Avion *' (or there is no acceptable conversion)

(By the way avion means airplane in spanish)
moramoga is offline   Reply With Quote
Old 02-06-2007, 10:14 AM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
Your class needs an assignment operator ie = it can be accomplished like so:
Code:
class Avion{
  private: 
    std::string name;
    int number;
    std::vector <double> some_vector;
...
  public:
    Avion operator=(Avion a){
      name = a.name;
      number = a.number;
      some_vector = a.some_vector;
      return *this;
    };
...
}
Or however it will fit to reassign every member from your class to the current class instance..
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A simple ambiguity regarding the thing that in java everything is passed by copy?? j.gohel Java 1 06-05-2006 03:22 PM
How to Nullifying the Arraylist Object?.. edwardmraj Java 1 06-16-2005 02:50 PM
How to get an ArrayList Object in servlet from JSP? edwardmraj Java 2 06-10-2005 08:15 AM
Struts santhini Java 1 05-16-2005 08:03 AM
working with Array Goong MS Technologies ( ASP, VB, C#, .NET ) 3 07-22-2004 12:14 PM


All times are GMT -8. The time now is 03:51 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting