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

Header file help

Name: Anonymous 2009-03-26 17:24

Yesterday I was assigned a project for my computer science class.
We're supposed to be using header files with our class definitions, but our teacher never really explained how header files work. This has lead me to a problem.

Here's what I'm looking at:
=====foo.h=====
class Foo
{
    private:
    const int MAX_ENTRIES;
    int array[MAX_ENTRIES];

    public:
    Foo();
};

=====foo.cpp=====
class Foo
{
    public:
    Foo::Foo()
    {
        MAX_ENTRIES = 25;
    }
}

As you can tell by my posting here, this isn't working. Is there anyway to define the size of the array using a named constant, or am I going to have to use a literal constant?

Name: Anonymous 2009-03-26 17:48

>>1
In the header
static const int MAX_ENTRIES = 25;
And you can omit private:
In the .cpp int Foo::Foo() { } with no class definition and no assignment to MAX_ENTRIES.

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