Okay, I’ve tried using Google-sensei and searching around on this website, and while I’ve found many posts about this error, I haven’t found any that have addressed enums. Also, all the ones I have seen have either been someone trying to assign one type to another, improper use of ‘new’, etc. As far as I can tell, that’s not the case in this instance.
As stated in the title, I’m getting an error conversion from 'KanjiCard*' to non-scalar type 'KanjiCard' requested when trying to compile the program I’m working on using g++.
I have a class named KanjiCard that has this publicly-defined enum:
enum KanjiCardType {
KANJI_CARD = 1,
KEYWORD_CARD = 2
};
The constructor for the class is defined as follows:
KanjiCard(char *cardText, int cardTextLength, int cardWidth, int cardHeight,
int cardX, int cardY, KanjiCardType cardType, SDL_Color textColor);
(I’m using char* instead of std::string because it’s easier to work with the libraries I’m using that way.)
I’m calling it to create new cards like so (this is where the error comes up):
KanjiCard currentCard = new KanjiCard(kanji_line, strlen(kanji_line),
CARD_WIDTH, CARD_HEIGHT, xPos, yPos, cardType, textColor);
cardType is defined as such: KanjiCard::KanjiCardType cardType = KanjiCard::KANJI_CARD;
I originally tried just passing in KanjiCard::KANJI_CARD where cardType is in that constructor call right now, but I got that error, so I’ve been trying everything I could think of to try and get it to work, including trying switching the cardType parameter in the constructor to *cardType and &cardType and messing around with the type of cardType in the call as well, to no avail.
As far as I can tell, cardType isn’t a pointer, so I really can’t figure out why I’m getting that message. Any help would be greatly appreciated, as I’m at my wit’s end trying to figure this out.
Edit: I should also mention that I also tried pulling the enum out of the class (and removing the KanjiCard:: preface, of course), and still had the same issue.
It’s not
cardTypethat’s the problem; it’scurrentCard. You wrote this:That’s assigning a pointer to a non-pointer type. You may have meant this:
…or you may have meant this:
The former of my suggestions will allocate a
KanjiCardon the heap.currentCardwill point to theKanjiCard. The latter will allocate it on the stack. It is aKanjiCard.The former you’ll have to manually
delete. The latter doesn’t need to bedeleted; it is valid within the scope it’s declared and once it goes out of scope, it’s invalid.The former you can access members of using
->. The latter you can access members of using..