Skip to main content
gamedev.net
🔒 Locked

Template Problem?

Started by Elwren May 16, 2003 at 10:10 AM 3 replies 300+ views
Original Post
Elwren
Elwren
Hey, I've been working on a project of mine and I use a container class I created to manage certain data types I might have. I call this class "sequence" and it uses a static filled array to hold the data. My problem is that I'm trying to convert this class to a
Oluseyi
Oluseyi
quote:
Original post by Elwren
The error I get is "C2512 - ''character'': no appropriate default constructor available".
Does the character class have a default constructor? Your sequence default constructor doesn''t pass any arguments to the object constructors of the elements it contains, so it invokes their default constructors. int and char (and all other basic types) effectively behave as though they possess default constructors which perform no initialization of the data they occupy.

Add this to your character class:

...
character() {}
...

If that breaks with the behavior of your character class, then it must always be dynamically allocated, so you should create a sequence of pointers to characters instead.
Lektrix
Lektrix
The declaration of sequence's data member calls the Item/value_type's default constructor. You have not implemented a default constructor for your character class.

Basically, the sequence class is OK, it is the character class that is causing the error.

For your character class, you must define a default constructor:


class character
{
public:
    character();
    ...
private:
    ...
};

character::character()
{
    ...
}


[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on May 16, 2003 11:25:38 AM]
Qw3r7yU10p!
Qw3r7yU10p!
so does character have a default constructor?
Elwren
Elwren
Blah stupid error. We never went over having objects in our container classes in my C++ course so I didn''t know. Anywho, I had a constructor but it took paramaters and I guess I needed to add those in my sequence declaration. Anywho, I added a default simple constructor that did nothing and it now works. Thanks!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.