Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Templating a Class

Name: Anonymous 2012-06-12 23:28

I've got a simple c++ syntax question here that kind of makes me want to tear my eyes out.

I've got a templated class I've made and I'm pretty sure it isn't working because of how I have the non-inlined functions defined. I haven't worked with templating a class before so I don't know how this part works. Or I could just be fuck-wrong, I don't know.

Any help would be massively appreciated.

#ifndef CELL_H_
#define CELL_H_

template <typename Offset = signed char, typename Symbol = wchar_t>
struct Cell
{
    Offset oX, oY;
    ConsoleColor fg, bg;
    Symbol sym;

    Cell() { }
    Cell(Offset oX, Offset oY,
        ConsoleColor fg, ConsoleColor bg, Symbol sym) { }

    Offset & operator [](int index);
    Offset const & operator [](int index) const;

    bool Show(int left, int top) const;
};
#endif

#include "StdAfx.h"
#include "Cell.h"

template <typename Offset, typename Symbol>
bool Cell<Offset,Symbol>::Show(int left, int top) const
{
    int tempx, tempy;
    tempx = left+(int)oX;
    tempy = top+(int)oY;
    if(tempx >= Console::WindowWidth ||
        tempy >= Console::WindowHeight ||
        tempx < 0 || tempy < 0)
        return false;
   
    Console::BackgroundColor = bg;
    Console::ForegroundColor = fg;
    Console::SetCursorPosition(tempx, tempy);
    Console::Write(sym);
    Console::ResetColor();
    return true;
}

Name: Anonymous 2012-07-04 14:26

go to /prog/

Don't change these.
Name: Email:
Entire Thread Thread List