ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
How are you compiling your code? Are your definitions for your class constructors and member functions in another file? They must be if they're not in the file you've shown. You need to include this file when you're compiling. For example, say the file containing your main() function is called "main.cpp" and the file containing your definitions for member functions and constructors is called "definitions.cpp", you should be able to compile with
g++ main.cpp definitions.cpp -o main,
assuming of course you're using g++.
Edit: you'll also need your class declaration present in your definitions file. Of course, the better way to do it would be to put your class declarations in header files and include those in both your main file and the file containing the definitions for your constructors and member functions. Edited again: Or, you just put everything in one file..
I am not following you, unfortunately I haven't programmed in C++ in 5-6 years and I wasn't a big C++ programmer back then, but this class is required and I am trying to do my best.
I am using g++ as my compiler.
Quote:
Are your definitions for your class constructors and member functions in another file? They must be if they're not in the file you've shown. You need to include this file when you're compiling.
My understanding is that I have defined everything so far. I do realize I didn't have a constructor or deconstructor for the Pair class so I have fixed this.
If you are willing, I would appreciate any explanation or help.
I am trying to find a good resource for relearning class and class templating right now.
I shall stop using the terms "declaration" and "definition", because I always get them the wrong way round.
Basically, you've only provided information about the member functions and constructions that exist, but you haven't specified what happens when those constructors/member functions are called.
You can put the code that runs when the constructors/member functions are called in the same file, for example
Code:
// A.h
class A
{
public:
A() { x = 0; }
int get_x() { return x; }
private:
int x;
};
Code:
// main.cpp - example program
#include <iostream>
#include "A.h"
using namespace std;
int main()
{
A myA;
cout << A.get_x() << endl;
return 0;
}
Obviously, you can put the whole lot in a single file (i.e. just merge the files above and then you just remove the "#include A.h" line).
You can also put the interface to the class - i.e. the code that says which members and constructors exist (but says nothing about what they do) in one file and the code for those in a separate file:
Code:
// A.h
class A
{
public:
A();
int get_x();
private:
int x;
};
Code:
// A.cpp - definitions for constructor and member function
#include "A.h"
A::A() { x = 0; }
int A::get_x() { return x; }
The main program will be identical to that given above, but when you compile, you'll need to include the A.cpp file:
Yeah I get where you are going, let me try something first and get back to you. I am just trying to get it to compile without actually "working", like compile without functionality at this point, as I am working on getting the functionality created.
You need to define the operator[] function for HashTable. The way you're using it, you need this signature:
Code:
//note this would have to be the HashedObj of Dictionary, not of HashTable
Object& operator[](const HashedObj & key);
Except that as you have written things, HashTable doesn't know anything about the objects it stores, so you won't be able to do this. If you don't want to change HashTable you could write Dictionary::insert as
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.