i get an error C2512 no appropriate default constructor available

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
aslanbey0158
Posts: 52
Joined: April 15th, 2017, 10:48 am

i get an error C2512 no appropriate default constructor available

Post by aslanbey0158 » March 16th, 2019, 6:18 pm

I watch hw3d videos. I am on 11. video . I write all codes which i saw on the video.
While "Graphics" is loaded, i get this error message.
Is there any hidden code which Chili didn't mention on the video?

User avatar
AP_
Posts: 10
Joined: October 20th, 2018, 2:37 am
Location: Motherland

Re: i get an error C2512 no appropriate default constructor available

Post by AP_ » March 17th, 2019, 7:49 am

I didn't get that far with the tutorials yet, but if you need code reference, checking out git commit history sounds like a better idea, rather than picking lines of code from the video.

https://github.com/planetchili/hw3d
"Idk if im having brain stop anyone have any advice on smart way to check 2 moving many unique step ur taking" ~Petrus

aslanbey0158
Posts: 52
Joined: April 15th, 2017, 10:48 am

Re: i get an error C2512 no appropriate default constructor available

Post by aslanbey0158 » March 17th, 2019, 11:50 am

The file is attached
Attachments
hw3d-11.rar
(3.17 MiB) Downloaded 141 times

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: i get an error C2512 no appropriate default constructor available

Post by albinopapa » March 17th, 2019, 9:07 pm

The problem is that the Graphics class doesn't have a default constructor, ie

Code: Select all

Graphics() = default;
Therefore in Window, you cannot store a Graphics object without initializing it, which you can't really do since it takes an HWND as it's constructor parameter and you don't get the HWND object until after the call to CreateWindowEx.

Chili uses a unique_ptr to a Graphics object to delay the initialization, which you do have, but you also have a Graphics object for some reason.

Code: Select all

// Chili's code
public:
	Keyboard kbd;
	Mouse mouse;
private:
	int width;
	int height;
	HWND hWnd;
	std::unique_ptr<Graphics> pGfx;

Code: Select all

// Your code
public:
	Keyboard kbd;
	Mouse mouse;
	Graphics gfx;
private:
	int width;
	int height;
	HWND hWnd;
	std::unique_ptr<Graphics> pGfx;
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: i get an error C2512 no appropriate default constructor available

Post by chili » March 18th, 2019, 7:21 am

I'm pretty sure I took a decent amount of time to talk about the deferred construction of the gfx object ;/
Chili

Post Reply