C++ Array Class Definition and Implementation, Not Declared in Scope?

user3062299

So I've been working on this all day and it almost works, but when I compile it with GCC it gives me three error messages:

arrayClassDriver.cpp:11: error: 'arrayClass' was not declared in this scope
arrayClassDriver.cpp:11: error: expected ';' before 'test'
arrayClassDriver.cpp:13: error: 'test' was not declared in this scope

Obviously it thinks arrayClass (the class instance) is a variable. How can I fix this?

Here's my definition of my class:

//Pre and Post Conditions
//arrayClass(int inputSize);
//Pre: A user defined int inputSize.
//Post: An array with size = inputSize has been created.

//~arrayClass();
//Pre: A dynamically created array.
//Post: The array has been deleted.

//void display();
//Pre: A dynamically created array.
//Post: List of all the values from the array.

//void resize(int newSize);
//Pre: A dynamically created array.
//Post: An array with the new size defined by the user.

//int& operator[](int location);
//Pre: None.
//Post: An operator which allows the programmer to access the array.

//int findMaxValue();
//Pre: A dynamically created array.
//Post: The max value of the array is returned.

//int findMinValue();
//Pre: A dynamically created array.
//Post: The min value of the array is returned.

//void sort();
//Pre: A dynamically created array.
//Post: A sorted array ready to be searched.

//int search(int key);
//Pre: A dynamically created array.
//Post: The sought value is returned.


#ifndef ARRAYCLASS_H
#define ARRAYCLASS_H

#include <iostream>

namespace arrayClass_Namespace
{
    class arrayClass
    {
        private:
            int *arr;
            const static int MAX_SIZE = 1000;
            int size;
        public:
            //Constructor
            arrayClass(int inputSize);
            //Destructor
            ~arrayClass();

            void display() const;
            void resize(int newSize);

            int& operator[](int);

            int findMaxValue();
            int findMinValue();
            void sort();
            int search(int key);
    };
}

#endif

Here's my implementation (I know I haven't written the code for the sort or the search yet):

#include <cassert>
#include "arrayClass.h"

arrayClass_Namespace::arrayClass::arrayClass(int inputSize)
{
    assert(inputSize < MAX_SIZE);
    size = inputSize;
    arr = new int[size];

    for (int index = 0; index < size; index++)
    {
        arr[index] = 0;
    }
}

arrayCLass_Namespace::arrayClass::~arrayClass()
{
    delete[] arr;
    arr = NULL;
}

void arrayClass_Namespace::arrayClass::display() const
{
    std::cout << "\nIndex" << "\t" << "Value";

    for (int index = 0; index < size; index++)
    {
        std::cout << index << "\t" << arr[index];
    }
}

int& arrayClass_Namespace::arrayClass::operator[](int location)
{
    assert(0 <= location && location < size);
    return arr[location];
}

int arrayClass_Namespace::arrayClass::findMaxValue()
{
    int max = 0;

    for (int index = 0; index < size; index++)
    {
        if (max < arr[index])
        {
            max = arr[index];
        }
        else if (max > arr[index])
        {
            max = max;
        }
    }
}

int arrayClass_Namespace::arrayClass::findMinValue()
{
    int min = arr[1];

    for (int index = 0; index < size; index++)
    {
        if (min > arr[index])
        {
            min = arr[index];
        }
        else if (min < arr[index])
        {
            min = min;
        }
    }
}

void arrayClass_Namespace::arrayClass::sort()
{

}

int arrayClass_Namespace::arrayClass::search(int key)
{

}

And finally, here's my driver (still need to add a few things, but I wanted to do this first):

#include <cstdlib>
#include "arrayClass.h"

int main()
{
    arrayClass test(10);

    test.display();

    return EXIT_SUCCESS;
}

Besides that, am I using the display member function correctly? It's been a little while since I've worked with classes, so any help is greatly appreciated.

Thanks in advance!

Vlad from Moscow

You forgot to specify namespace for arrayClass in this statement

arrayClass test(10);

Shall be

arrayClass_Namespace::arrayClass test(10);

Or you could write

#include <cstdlib>
#include "arrayClass.h"

int main()
{
    using arrayClass_Namespace::arrayClass;

    arrayClass test(10);

    test.display();

    return EXIT_SUCCESS;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Codeblocks: 'Class' was not declared in this scope

From Dev

Class objects not declared in scope

From Dev

Why must a method be declared in a C++ class definition?

From Dev

Not declared in scope - friend comparator class for priority_queue C++

From Dev

c++ class not declared in scope - called from main

From Dev

Function 'not declared in this scope' when using class in C++

From Dev

'Class Instance Object' was not declared in this scope

From Dev

C++ - Scope of the object created at the end of class definition

From Dev

C++ - Scope of the object created at the end of class definition

From Dev

Including header files in C++ (class definition and method implementation)

From Dev

definition macro implementation in C

From Dev

'TRUE' was not declared in this scope C++

From Dev

error: was not declared in this scope with C++

From Dev

C++ - stoi() was not declared in this scope

From Dev

error: was not declared in this scope with C++

From Dev

string is not declared in this scope C++

From Dev

C++ - stoi() was not declared in this scope

From Dev

not declared in this scope error, c++

From Dev

Implementation after class method definition

From Dev

Signal not declared in this scope/undefined reference to class::method

From Dev

class not declared in scope - even though .h was included

From Dev

Derive from class declared in private scope

From Dev

Signal not declared in this scope/undefined reference to class::method

From Dev

Qt: Custom derived class not declared in scope

From Dev

"Variable was not declared in this scope" in C and C++

From Dev

Static objects of nested class can be declared without class definition

From Dev

Should a class definition be put in the global or local scope?

From Dev

Template class array definition is not type name, static or enumerator C++

From Dev

gets() & puts() not declared in scope in dev c++

Related Related

  1. 1

    Codeblocks: 'Class' was not declared in this scope

  2. 2

    Class objects not declared in scope

  3. 3

    Why must a method be declared in a C++ class definition?

  4. 4

    Not declared in scope - friend comparator class for priority_queue C++

  5. 5

    c++ class not declared in scope - called from main

  6. 6

    Function 'not declared in this scope' when using class in C++

  7. 7

    'Class Instance Object' was not declared in this scope

  8. 8

    C++ - Scope of the object created at the end of class definition

  9. 9

    C++ - Scope of the object created at the end of class definition

  10. 10

    Including header files in C++ (class definition and method implementation)

  11. 11

    definition macro implementation in C

  12. 12

    'TRUE' was not declared in this scope C++

  13. 13

    error: was not declared in this scope with C++

  14. 14

    C++ - stoi() was not declared in this scope

  15. 15

    error: was not declared in this scope with C++

  16. 16

    string is not declared in this scope C++

  17. 17

    C++ - stoi() was not declared in this scope

  18. 18

    not declared in this scope error, c++

  19. 19

    Implementation after class method definition

  20. 20

    Signal not declared in this scope/undefined reference to class::method

  21. 21

    class not declared in scope - even though .h was included

  22. 22

    Derive from class declared in private scope

  23. 23

    Signal not declared in this scope/undefined reference to class::method

  24. 24

    Qt: Custom derived class not declared in scope

  25. 25

    "Variable was not declared in this scope" in C and C++

  26. 26

    Static objects of nested class can be declared without class definition

  27. 27

    Should a class definition be put in the global or local scope?

  28. 28

    Template class array definition is not type name, static or enumerator C++

  29. 29

    gets() & puts() not declared in scope in dev c++

HotTag

Archive