Advertisement

Need help with a constructor

Started by September 07, 2002 12:52 AM
3 comments, last by Quiggy 22 years, 3 months ago
Can anybody tell me whats wrong with this constructor? Can I even do this? No matter what I do to it I can''t get the darn thing to compile. Here''s the code. I first set up some constants in the header file and further down set up my class. const int SCREEN_WIDTH = 75; // This is the width of our window const int SCREEN_HEIGHT = 23; // This is the height of our window //************************************ class CBuffer { private: CHAR_INFO m_Screen[SCREEN_WIDTH * SCREEN_HEIGHT]; static const COORD m_Size; public: CBuffer() : m_Screen(), m_Size() {} // Constructor }; const COORD CBuffer::m_Size = {SCREEN_WIDTH, SCREEN_HEIGHT}; //************************************ And here''s the error I get. error C2438: ''m_Size'' : cannot initialize static class data via constructor Error executing cl.exe. Any help would be greatly appreciated.
Just remove m_Size from the member initialization list.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Advertisement
Thanks for the quick response! Works wunderbar now!

Actually I've added onto it again and have been stuck trying to get a function working for a few hours now. Maybe somebody can tell me whats going on with it now. The compiler always chokes on the GetScreenCharInfo() function within my class. I've tried formating it many ways using array braces and pointer notation, but I none of that works.


class CBuffer {
private:
CHAR_INFO m_Screen[SCREEN_WIDTH * SCREEN_HEIGHT];
static const COORD m_Size;

public:
CBuffer() : m_Screen() {}; // Constructor
void SetScreenChar(int index, char a) { m_Screen[index].Char.AsciiChar = a;}
void SetScreenAtrb(int index, WCHAR a) { m_Screen[index].Attributes = a;}
int GetSizeY() { return m_Size.Y; }
int GetSizeX() { return m_Size.X; }
COORD GetSizeCoord() { return m_Size; }
CHAR GetScreen(int x) { return m_Screen[x].Char.AsciiChar; }
CHAR_INFO GetScreenCharInfo() { return m_Screen;}
};
const COORD CBuffer::m_Size = {SCREEN_WIDTH, SCREEN_HEIGHT}; // Constructor



I'm calling the function from this line in my main.cpp file.


WriteConsoleOutput(hOutput, GameScreen.GetScreenCharInfo(), GameScreen.GetSizeCoord(), zeroZero, &drawRect);

Error message is
error C2664: '__thiscall _CHAR_INFO::_CHAR_INFO(const struct _CHAR_INFO &)' : cannot convert parameter 1 from 'struct _CHAR_INFO [1725]' to 'const struct _CHAR_INFO &'
Reason: cannot convert from 'struct _CHAR_INFO [1725]' to 'const struct _CHAR_INFO'

I assume it has something to do with const, but I just have no idea what.

As usual any help is appreciated.

P.S. what are the tags to put code in the window?



[edited by - Quiggy on September 7, 2002 6:58:10 AM]
You are returning a CHAR_INFO rather than a CHAR_INFO* (look at the method GetScreenCharInfo).
Ack! I was throwing that asterick and ampersand everywhere but in the place where it had to go. Now that I see it though, it actually makes sense. I knew that I had to pass along the whole array, but was unsure how to do it.

Anyways, thanks again for the help. Now I just have to figure out my 2 unresolved externals.

Quiggy.

This topic is closed to new replies.

Advertisement