This is the weirdest bug I have gotten yet. Its late, and I can't figure out why this is not working....I thought I had the constructor set up right. I am sorry that I am asking for so much help, but I have learned a LOT in these past few days as well :) Learning all these new pieces of code that can be used to help manipulate data :D

1>AoE2Wide.cpp(323): error C2440: 'initializing' : cannot convert from 'int' to 'AoE2Wide::Item *'
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>AoE2Wide.cpp(323): error C2078: too many initializers

class Item
	{
	public:
		int Pos;
		int ReferenceValue;
		std::string Type;
		int Parameter;
		std::string Comments;
		std::string Asm;
		int OriginalPos;
		Item(int p, int rf, std::string tp, std::string cm)
		{
			Pos = p;
			ReferenceValue = rf;
			Type = tp;
			Comments = cm;
		}
	};
int rf = atoi(tokens2.at(1).c_str()); // this is supposed to convert it to an int
			int Pos;
			sscanf_s(tokens2.at(0).c_str(), "%x", &Pos); // supposed to convert to an int
            auto item = new AoE2Wide::Item{Pos, rf, "", ""};

Maybe your compiler doesn't completely support C++0x initializations yet.

What happens if you replace the curly braces with parentheses in the last line of code in your example, and change "auto" to "AoE2Wide::Item*" ?

auto item = new AoE2Wide::Item{Pos, rf, "", ""};

Your declaration of "Item" is lower case here, though the class itself is uppercase.

auto Item * AoE2Wide= new Item(Pos, rf, "", "");

Does this work? Or am I misunderstanding your intention?

I'm pretty sure you can't use the "new" header without a pointer, since new allocates the memory in the heap and couldn't be accessed without the pointer, since it returns the address of the new allocation.

Make sure to also use a "delete" header, as such:

delete AoE2Wide;

when finished.


Unless there's some completely new usage of "new" I'm not aware of, in which case ignore my ramble.

Edited 5 Years Ago by Red Goose: n/a

Comments
Gave a clear an accurate answer :)

Your declaration of "Item" is lower case here, though the class itself is uppercase.

auto Item * AoE2Wide= new Item(Pos, rf, "", "");

Does this work? Or am I misunderstanding your intention?

It's a C++0x usage. It is a request to declare a variable named "item" of the same type as that returned by the expression "new Item(<arguments>)"

The curly braces are also part of C++0x. That's part of why I suggested that maybe your compiler doesn't support it yet--the C++0x standard isn't even finished yet.

It's a C++0x usage. It is a request to declare a variable named "item" of the same type as that returned by the expression "new Item(<arguments>)"

Hm, never heard of it. I don't think my compiler would allow me to do that either.

Just got onto my laptop, it was those dumb curly braces. Ty :) I need more sleep I think xD

This question has already been answered. Start a new discussion instead.