Trouble returning an object from a class I created

David Velasquez

I have this class (hashMap.h):

#pragma once

#include <iostream>
#include <vector>
#include <string>
#include "functions.h"
using std::cout;
using std::vector;
using std::endl;
using std::string;

class hashMap
{
public:
    explicit hashMap(int hashEntrySize = 101) : hashVector(nextPrime(2 * hashEntrySize)), currentSize{ 0 }
    {}

    bool containsKey(const string & searchKey);
    bool containsVector(const vector<string> searchVector);
    void insert(const string & keyTarget, const vector<string> & insertVector);
    void insertAfterReHash(const string & keyTarget, const vector<string> & insertVector);

    int getCurrentSize() const;
    void assignKey(string & newKey);

private:
    enum EntryType { ACTIVE, EMPTY, DELETED };
    struct hashEntry
    {
        vector<string> vectorValue;
        EntryType status;
        int keyID;
        string key;

        hashEntry(EntryType s = EMPTY)
            :status(s), keyID{ -1 } {}
    };

    size_t hashFunction(const string & key);
    bool isActive(int currentPos) const;
    int findPos(const string & keyTarget);
    void reHash();

    vector<hashEntry> hashVector;
    int currentSize;
};

And a function header file (functions.h):

#pragma once
#include <iostream>>
#include <vector>
#include <string>
#include <fstream>

using std::string;
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::ifstream;
using std::getline;


hashMap computeAdjacentWords(const vector<string> & words) //error at this line
{
    hashMap hm(500);

    //do stuff with object

    return hm;
}

And the main file:

#include <iostream>>
#include <vector>
#include <string>
#include <fstream>
#include "hashMap.h"

using std::string;
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::ifstream;
using std::getline;

int main()
{
    vector<string> words;
    string line;
    ifstream dictionaryFile;

    dictionaryFile.open("largedictionary.txt");
    words = readinWords(dictionaryFile);
    dictionaryFile.close();

    hashMap hm = computeAdjacentWords(words);

    return 0;
}

I created the hashMap class and I want to be able to return a hashMap object, but this is giving me an error of "Error C4430 missing type specifier - int assumed." What am I doing wrong?

axiac

I put the code in files and nicely asked the compiler to do its job. This is the first warning from the list:

$ cc main.cpp -c
In file included from main.cpp:5:
In file included from ./hashMap.h:6:
./functions.h:16:1: error: unknown type name 'hashMap'
hashMap computeAdjacentWords(const vector<string> & words) //error at this line
^

The compiler doesn't know what hashMap is. When it reaches the line with the error, the hashMap symbol was not yet declared or defined.

You shouldn't define functions in header files.

Rename functions.h to functions.cpp, add #include "functions.h" at the end of the list of includes.

Create a new file functions.h that contains only the declarations of the functions (the function header) and the types they use:

#ifndef __FUNCTIONS_H__
#define __FUNCTIONS_H__

#pragma once
//#include <iostream>
#include <vector>
#include <string>
//#include <fstream>
#include "hashMap.h"

using std::string;
using std::vector;
// Do you really need all these types here?
using std::cout;
using std::endl;
using std::cin;
using std::ifstream;
using std::getline;


hashMap computeAdjacentWords(const vector<string> & words);

#endif // __FUNCTIONS_H__

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do i access a specific object from with in the class it was created from

From Dev

Delete this and then returning created object

From Dev

Delete this and then returning created object

From Dev

Returning a generic object on Java from abstract class

From Dev

Creating Array of Objects from Class I Created

From Dev

Programming a game in java. I need to read class files from a related directory, and return an object created from those

From Dev

Programming a game in java. I need to read class files from a related directory, and return an object created from those

From Dev

Returning template class object

From Dev

Returning an Object In a PHP Class

From Dev

returning a class object with a pointer

From Dev

I am having trouble calling code from a class

From Dev

Trouble when returning non pointer object in a block

From Dev

Having trouble returning a templated struct object pointer

From Dev

Trouble returning object through some Callbacks

From Dev

Having trouble returning a templated struct object pointer

From Dev

Trouble overriding toString on object/class

From Dev

How do I ensure only one instance of the object of the class is created?

From Dev

Can I get the function of the base class on object is created as interface

From Dev

Making an object created by JSON.parse inherit from another class

From Dev

Having trouble returning a file from the server

From Dev

angularjs - Trouble returning data from a factory

From Dev

Trouble deleting dynamically created buttons from form

From Dev

Returning a date from a class

From Dev

Is the Class object A created when the JVM loads class A, or when I call A.class?

From Dev

NewGlobalRef/DeleteGlobalRef when returning object created in JNI

From Dev

How to get the name of child class from base class when an object of child class is created

From Dev

JavaScript items missing from Object I just created

From Dev

I am having some trouble using variables from one class in my driver class

From Dev

I am having some trouble using variables from one class in my driver class

Related Related

  1. 1

    How do i access a specific object from with in the class it was created from

  2. 2

    Delete this and then returning created object

  3. 3

    Delete this and then returning created object

  4. 4

    Returning a generic object on Java from abstract class

  5. 5

    Creating Array of Objects from Class I Created

  6. 6

    Programming a game in java. I need to read class files from a related directory, and return an object created from those

  7. 7

    Programming a game in java. I need to read class files from a related directory, and return an object created from those

  8. 8

    Returning template class object

  9. 9

    Returning an Object In a PHP Class

  10. 10

    returning a class object with a pointer

  11. 11

    I am having trouble calling code from a class

  12. 12

    Trouble when returning non pointer object in a block

  13. 13

    Having trouble returning a templated struct object pointer

  14. 14

    Trouble returning object through some Callbacks

  15. 15

    Having trouble returning a templated struct object pointer

  16. 16

    Trouble overriding toString on object/class

  17. 17

    How do I ensure only one instance of the object of the class is created?

  18. 18

    Can I get the function of the base class on object is created as interface

  19. 19

    Making an object created by JSON.parse inherit from another class

  20. 20

    Having trouble returning a file from the server

  21. 21

    angularjs - Trouble returning data from a factory

  22. 22

    Trouble deleting dynamically created buttons from form

  23. 23

    Returning a date from a class

  24. 24

    Is the Class object A created when the JVM loads class A, or when I call A.class?

  25. 25

    NewGlobalRef/DeleteGlobalRef when returning object created in JNI

  26. 26

    How to get the name of child class from base class when an object of child class is created

  27. 27

    JavaScript items missing from Object I just created

  28. 28

    I am having some trouble using variables from one class in my driver class

  29. 29

    I am having some trouble using variables from one class in my driver class

HotTag

Archive