Archived

This topic is now archived and is closed to further replies.

Please help with weird compile error

This topic is 5009 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For some reason code that has been tested and worked fine before now creates a compile time error I don''t understand. It says could not find a match for Material_MD3::MaterialMD3(const MaterialMD3) Error code E2285 in C++ builder. The error happens in a file called memory.stl. I am using the template in vector.h and when I push_back an item this error is created. Another weird thing is that Material_MD3 is a structure, not a class and this error obviously is looking for a constructor. Any ideas on what might be going wrong would be greatly appreciated.

Share this post


Link to post
Share on other sites
Perhaps the declaration should be
Material_MD3::MaterialMD3(const MaterialMD3 & )      
instead of
Material_MD3::MaterialMD3(const MaterialMD3)     


Or perhaps it needs a copy constructor and none (including the default) is available for some reason.


[typos]


[edited by - JohnBolton on March 27, 2004 5:05:30 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
sturctures also have contructors.
The only difference between a class and a struct is that class default to private and structs public

Share this post


Link to post
Share on other sites
quote:
There is a subtle difference between Material_MD3 and MaterialMD3

Yup, that's just plain evil...

[edited by - amag on March 26, 2004 8:24:54 AM]

Share this post


Link to post
Share on other sites
Uhm, maybe if you posted some of the offending code, it would be easier to help you.
Anyway, here are some thoughts:

Material_MD3::Material_MD3(const Material_MD3)
// should probably be

Material_MD3::Material_MD3(const Material_MD3 &)
// for a copy-ctor


If you have defined a ctor for Material_MD3, then it might be a good thing to have both a copy ctor and a default ctor (one that takes no args) if used with STL.

Note that if you define one ctor for your class (no matter what it looks like), the compiler won''t generate any of the ''free'' ones (copy ctor and default ctor).

Share this post


Link to post
Share on other sites
I know why it''s happening now I just don''t know what to do about it. One of the item in Material_MD3 is a class that has a copy constructor. I commented out this copy constructor and everything worked fine so that is definitely the source of the problem.

Here is Material_MD3

typedef struct {
char strName[255];
char strFile[255];
unsigned char color[3];
float fColor[3];
int texureId;
float uTile;
float vTile;
float uOffset;
float vOffset;
Textures Tex; // this is the class i mentioned
}Material_MD3;

The Material_MD3 list is declared like this
vector pMaterials;

The area of code that causes error is this

Material_MD3 Mat;

if(pSkins[Counter][strlen(pSkins[Counter])-3] == ''p'')
{
if(pSkins[Counter][strlen(pSkins[Counter])-2] == ''c'' && pSkins[Counter][strlen(pSkins[Counter])-1] == ''x'')
{
pSkins[Counter][strlen(pSkins[Counter])-3]=''b'';
pSkins[Counter][strlen(pSkins[Counter])-2]=''m'';
pSkins[Counter][strlen(pSkins[Counter])-1]=''p'';
}
}
strcpy(Mat.strFile,PathName);
strcat(Mat.strFile,pSkins[Counter]);
Model.pMaterials.push_back(Mat); // here causes problem

Share this post


Link to post
Share on other sites
quote:
Original post by Leroy1891
I want to see if adding a copy constructor to Material_MD3 will resolve the problem but I've never added a constructor to a structure before. how would i do it?
Same as adding one to a class.

A class and a struct are all but identical, except that a struct defaults to public access/public inheritance and a class defaults to private access/private inheritance. Anything that can do to a class can be done to a struct and v.v.

Make sure that your copy constructor does *deep* copies on those char[]s and any other pointers or arrays (ie, copy the contents and not just the address), or you'll have some fun bugs to track down.

EDIT: Also, in C++, the typedef struct {...} Material_MD3; trick is no longer necessary. struct Material_MD3 {...}; is just as valid.

[edited by - ze_jackal on March 26, 2004 11:14:10 PM]

Share this post


Link to post
Share on other sites