Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 17 Apr 2013
Offline Last Active Dec 05 2014 07:19 AM

Topics I've Started

member access into incomplete type

16 November 2014 - 02:31 PM

Hello. Thanks in advance for reading.

In this pattern http://gameprogrammingpatterns.com/component.html
with the example:
Bjørn contains an instance of inputComponent and calls its method like input_.update(this*); this method then accesses members of bjørn, like bjorn.velocity -= WALK_ACCELERATION;
I didn’t understand how this could work, each object accessing each others members/methods  without causing a dependancy loop. So I made a little test program, but I can’t get it to work. I get the error 'member access into incomplete type 'object''.Am I missing something? Or not understanding the pattern?
My basic test:
#include "component.h"
class object{
    component _component;
    const char* getSomething();
    void doSomething();
#include "object.h"

void object::doSomething(){

const char* getSomething(){
    return "something";
#include <iostream>

class object;

class component{
    void accessThis(object& obj);
#include "component.h"

void component::accessThis(object& obj){
    std::cout<< "got" << obj.getSomething() << ".\n";

ncurses: problem with highlighting a line of characters

24 October 2013 - 10:21 AM

This is quite a specific question, but I couldn't find a forum on ncurses so I thought I might as well ask it here.

I am writing a program using ncurses that needs a function to highlight a line of characters on the screen. I started writing this function that took the x & y coordinates of a character on the screen and the length of characters after that to highlight. Whilst doing this I noticed that if I highlighted the last character in a row (maxX-1 in my example) it highlighted that character (as expected), and if I highlighted just the character before that (maxX-2) it also works. But if I do both, it highlights the whole row/line. Also, if there are characters in those spaces other than the 'space' character it works too, but for my program I need to be able to highlight empty spaces as well.


To highlight I am using inch() to get the character and addch() to print it because I am using some alternate characters that chgat() replaces with normal characters.


If anyone has any ideas why it could be doing this, that would be a great help, since this makes no sense to me and there must be something i'm missing.


#include <ncurses.h>


int main(){







    int maxX=0, maxY=0;

    getmaxyx(stdscr, maxY, maxX);


    init_pair(5, 15, 10);



    mvaddch(5, maxX-1, inch());     //works as expected


    mvaddch(6, maxX-1, inch());

    mvaddch(6, maxX-2, inch());     //highlights whole line for some reason? whyyy? sad.png


    mvaddch(7, maxX-1, inch());

    mvaddch(7, maxX-2, 'c');        //works as expected







    return 0;


code review - basic state system

06 September 2013 - 04:46 AM

I am writing a simple board game where the players place pieces on a board. (theres more to it than that, but you get the idea)


I needed a system where, on one screen the player can view the board and select tiles, and on the other they can select from a menu the type of tile they want to place.


For this I needed two 'states', each one handling input and output differently. So I created these as classes, both inheriting from the 'state' class. The thing I have had difficulty with is switching between these classes, since they cant see each other, and how the current state pointer switches from one state to the next will depend on the original state. What I have done is given the state class a 'states' static vector, which stores pointers to all the states that have been created, and a non-static 'keys' vector which stores the input needed to access that state from the this state (so the two vectors sort of line-up). 


Anyway this seemed kind of messy and there is probably a reason why you shouldn't do this and i'm probably doing everything wrong anyway. So I'm posting this on here to ask for some feedback before I make it even worse.




Here is the program. (its not actually a board game here. I've reduced it to just the basic state system)

Code Review - Battleship

18 April 2013 - 08:10 AM

So, I have been learning the basics of C++ by writing a simple Battleships program (with the aid of tutorials from thenewboston.org and this Youtube channel).

Well, I say simple, but to be honest it's taken me quite a bit longer than I was expecting. I guess speed is something that comes with practice, but the program seems to work anyway.


The program has basic AI, so that when the computer player hits a human player's ship once, it will try to find the rest of that ship.

The ships are also randomly positioned.


Here  it is.


I am posting this on here because I am thinking of doing something more complex (a roguelike, using ncurses). Since I'm only teaching myself, as far as I know I might be doing things inefficiently, or even doing everything completely wrong. So I want to make sure I've got the basics down first.


One thing i was unsure about was in the computer player class. There are 4 functions sharing a bunch of variables, and I defined them as members of that class. I thought that passing pointers to them all from function to function wouldn't be as clear and would look messy, but this means that they take up memory even when they're not being used.


If anyone could scan through it and tell me anything I'm doing wrong, that would be really helpful. Thanks.