Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 51 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next
Author Message
 Post Posted: April 13th, 2017, 3:46 pm 
 

Joined: April 13th, 2017, 11:07 am
Posts: 5
chili wrote:
You're missing the default constructor for the segment

You want like Segment() = default;


Where do i put the default constructor for the segment? I wrote it as Segment() = default; under the segment class and it still has the same error of trying to reference a deleted function.

1>c:\users\Adagio\desktop\t14-snek-start\engine\snake.cpp(5): error C2280: 'Snake::Segment::Segment(void)': attempting to reference a deleted function
1>c:\users\Adagio\desktop\t14-snek-start\engine\snake.h(12): note: see declaration of 'Snake::Segment::Segment'


Top 
 Profile  
Reply with quote  
 Post Posted: April 13th, 2017, 5:45 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2782
Location: Oklahoma, United States
Adagio wrote:
chili wrote:
You're missing the default constructor for the segment

You want like Segment() = default;


Where do i put the default constructor for the segment? I wrote it as Segment() = default; under the segment class and it still has the same error of trying to reference a deleted function.

1>c:\users\Adagio\desktop\t14-snek-start\engine\snake.cpp(5): error C2280: 'Snake::Segment::Segment(void)': attempting to reference a deleted function
1>c:\users\Adagio\desktop\t14-snek-start\engine\snake.h(12): note: see declaration of 'Snake::Segment::Segment'

I'm going to say that this is the culprit
Quote:
note: 'Snake::Segment::Segment(void)': function was implicitly deleted because a data member 'Snake::Segment::loc' has either no appropriate default constructor or overload resolution was ambiguous

You probably did the same as someone else in the forum and make a constructor for the Location struct. Remove any Location::Location constructors, and you should be ok.

_________________
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


Top 
 Profile  
Reply with quote  
 Post Posted: April 13th, 2017, 5:51 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2782
Location: Oklahoma, United States
Here's a link to the previous persons experience with same issue
http://planetchili.net/forum/viewtopic.php?f=3&t=3977&start=10

_________________
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


Top 
 Profile  
Reply with quote  
 Post Posted: April 14th, 2017, 2:31 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3448
Location: Japan
Ah right, I was looking for that! Thanks for posting the link. ;)

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post Posted: April 14th, 2017, 3:26 am 
 

Joined: April 13th, 2017, 11:07 am
Posts: 5
Right I removed the constructor i made for the location struct and it built successfully. Thanks for the help guys!


Top 
 Profile  
Reply with quote  
 Post Posted: April 14th, 2017, 2:22 pm 
 

Joined: April 13th, 2017, 11:07 am
Posts: 5
Hello again my friends!
I've finished tutorial 14b and was trying out the homework section and I have a question regarding the spawning of the obstacle.
I looked through the github file Chili put up in the wiki and there's several areas I'm unclear on.
First, what happens when u set a boolean statement to an array ( e.g. bool hasObstacle[width * height] = { false }; )? does it set up a boolean for each cell in the grid?

Secondly, the boolean function you have set up in board.cpp :
bool Board::CheckForObstacle( const Location & loc ) const
{
return hasObstacle[loc.y * width + loc.x];
}


why do you take loc.y * width + loc.x inside the array number an what does that statement return exactly?

I'm guessing you are checking each cell in the grid to see if there is an obstacle in the grid and to draw 1 if there isn't according to the draw obstacle function. I just don't get what this line in particular: "return hasObstacle[loc.y * width + loc.x];" mean. :?


Top 
 Profile  
Reply with quote  
 Post Posted: April 14th, 2017, 9:59 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2782
Location: Oklahoma, United States
Quote:
First, what happens when u set a boolean statement to an array ( e.g. bool hasObstacle[width * height] = { false }; )? does it set up a boolean for each cell in the grid?

Kind of, it makes an array with the same number of bool elements as the grid.

Quote:
Secondly, the boolean function you have set up in board.cpp :
bool Board::CheckForObstacle( const Location & loc ) const
{
return hasObstacle[loc.y * width + loc.x];
}

why do you take loc.y * width + loc.x inside the array number an what does that statement return exactly?


If you have made it this far in the tutorials, you would have covered functions. Look at the function declaration and it tells you want it returns.
As far as ( loc.y * width + loc.x ) goes, this is covered in one of the tutorials, but I don't remember if chili covered it at that point or not. Each row is width wide, so loc.y being the vertical axis ( row number ), when you multiply the row number by the number of columns, you get an offset to the beginning of that row. When you add loc.x to it, you get the location of the cell in the array.

Imagine you have a 10x10 grid
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
...

If you want to know the index of the cell in the array you want, you multiply row number by the width of the grid.
Example ( x = 3, y = 2, width = 10 )
row_offset = y * width // 2 * 10 = 20
index = x + row_offset // 20 + 3 = 23
So now
return hasObstacle[loc.y * width + loc.x];
would return a bool from the array hasObstacle at index 23.

_________________
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


Top 
 Profile  
Reply with quote  
 Post Posted: April 15th, 2017, 3:29 am 
 

Joined: April 13th, 2017, 11:07 am
Posts: 5
I see. So ( loc.y * width + loc.x ) is the input of the individual coordinates of the cell in the grid. I was having trouble visualising what it meant but now i understand. Thanks for the explanation @albinopapa!
So bool CheckForObstacle(const Location& loc) const; just returns the bool element of a specific coordinate { x, y } in the grid!


Top 
 Profile  
Reply with quote  
 Post Posted: April 15th, 2017, 6:09 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2782
Location: Oklahoma, United States
@Adagio
Yes, it returns the bool element at the index of hasObstacle specified by the Location loc object with the values stored at members x and y.

_________________
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


Top 
 Profile  
Reply with quote  
 Post Posted: August 31st, 2017, 12:08 am 
 

Joined: August 13th, 2017, 12:12 pm
Posts: 1
I got thus same error. Even with the default constructor added. I ended up taking off the = default and created a body for the constructor where I just set the value of c = Colors::Cyan;
The error moved to Location has no default and I added one.
Location() = default;

I'm still a little confused why a couple of us got these errors and not everyone. But in the end, if it compiles ok, I'll live with it.

Geezer.

Aaaaaand Now I just found all the other posts on here. I do have a Location constructor, so there's the problem. Thanks.


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 51 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron