Windows form not recognizing custom class

Working on a group project, our group has not been able to use our custom HashTable class inside a Windows form (using Visual Studio 2010). Below is all the (hopefully) relevant code. The errors we get when trying to compile this are:

error C2059: syntax error : 'constant' (LINE 42)
error C2227: left of '->insert' must point to class/struct/union/generic type (LINE 48)

Form1.h (lots of fluff trimmed out):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "hashTable.h"

namespace studentHashExample {
	
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:	
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}
		
	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}


	private: System::Windows::Forms::Button^  clearButton;
	private: System::Windows::Forms::Button^  insertButton;
	private: System::Windows::Forms::Button^  searchButton;
		HashTable myTable(19);
/* rest of form controls and auto-generated code snipped */

private: System::Void insertButton_Click(System::Object^  sender, System::EventArgs^  e) { //insert button event
			 StudentProfile myProfile;
			 int::TryParse(studentIDTextBox->Lines[0],myProfile.idNumber); 
			 myTable->insert(myProfile);
		 }	
/* other form event functions snipped */


hashTable.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <vector>
#include "StudentProfile.h" // StudentProfile struct defined here

class HashTable
{
private:
	int size;
	vector<StudentProfile> table;
public:
	HashTable(int size);
	bool insert(StudentProfile newProfile);
	bool remove(int IDnum)
	void clear();
	bool search(int IDnum);
	//void display(int caseNum);
}


Could anyone shed some insight as to how to make our HashTable object be recognized and used by the GUI form? We've devolved to pasting the HashTable declaration in every possible spot. There is some deeper problem that we're not seeing.
Last edited on
You are creating an object then dereferencing it like its a pointer(->)
Maybe declare as a pointer and new in the ctor
1
2
3
4
5
private: HashTable* myTable; //not sure if managed pointer is needed ie:^

Form1(){
myTable = new HashTable(19);
}


FWIW i've done very little managed c++ but hopefully this will point you in the right direction.
Last edited on
1
2
3
4
5
private: System::Void insertButton_Click(System::Object^  sender, System::EventArgs^  e) { //insert button event
			 StudentProfile myProfile;
			 int::TryParse(studentIDTextBox->Lines[0],myProfile.idNumber); 
			 myTable.insert(myProfile);
		 }


Thanks for the reply. Using myTable.insert() like normal still produces the error:

error C2228: left of '.insert' must have class/struct/union (line 4)
You cant create a constant object in a class, make myTable a pointer.
Thanks for the tip guys; using a pointer allows it to build. Now to test and debug...
Last edited on
Topic archived. No new replies allowed.