Parameter error:

I created member variables in the MainFrame class this way I could access them from anywhere:

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
#include "GUI.h"
#include <wx/msgdlg.h>
#include <wx/filename.h>
#include <string>
#include "im.h"
#include "dm.h"
#include "register.h"
#include "controlUnit.h"
#include "ALU.h"

//// end generated include

/** Implementing GUI_MainFrame */
class MainFrame : public GUI_MainFrame
{
	InstructionMemory im; // member variable
	ControlUnit cu;
	Register reg;
	DataMemory dm;
	ALU alu;
	protected:
		// Handlers for GUI_MainFrame events.
		void OnALUReset( wxCommandEvent& event );
		void OnControlUnitReset( wxCommandEvent& event );
		void OnQuit( wxCommandEvent& event );
		void OnAbout( wxCommandEvent& event );
		void OnOpen( wxCommandEvent& event );
		void OnStart( wxCommandEvent& event );
		void OnPause( wxCommandEvent& event );
		void OnStop( wxCommandEvent& event );
		void OnStatusReset( wxCommandEvent& event );
		void OnImLoad( wxCommandEvent& event );
		void OnImLoad2();
		void OnImLoadDecode( const wxString &string );
		void OnDmLoadDecode( const wxString &string );
		void OnImReset( wxCommandEvent& event );
		void OnDataLoad( wxCommandEvent& event );
		void OnDataLoad2();
		void OnDataReset( wxCommandEvent& event );
		void OnRegisterReset( wxCommandEvent& event );
		void OnMenuClearAll( wxCommandEvent& event );
		void OnNormalSpeed( wxCommandEvent& event );
		void OnDemoSpeed( wxCommandEvent& event );
	public:
		/** Constructor */
		MainFrame( wxWindow* parent );

	//// end generated class members
};


Here is im.h:
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <iostream>
#include <fstream>
#include <string>
#include <limits>
#include <vector>
#include <math.h>
#include "mainframe.h"

using namespace std;

class InstructionMemory {
private:
	vector<string> instmem;
	string intToBinary(int num)
	{
		string result;
		for(int i =1; i<=6; i++)
			if(num/pow(2.0,6-i)>=1)
			{
				result+='1';
				num=num-(int)pow(2.0,6-i);
			}
			else
				result+='0';
		return result;
	};
public:
	string InstructionMemory::fetch(int pc)
	{
		return instmem[pc];
	};

	int InstructionMemory::size()
	{
		return instmem.size();
	};
	void InstructionMemory::decode(string filename, MainFrame* theFrame)
	{
		ifstream file;
		file.open(filename.c_str());
		string tempstring;
		int tempInt, numArgs;
		while(file.good())
		{
			file >> tempstring;
			if(tempstring=="ADD")
			{
				instmem.push_back("000001");
				numArgs=3;
			}
			else if (tempstring=="SUB")
			{
				instmem.push_back("000010");
				numArgs=3;
			}
			else if (tempstring=="MULTI")
			{
				instmem.push_back("000011");
				numArgs=3;
			}
			else if (tempstring=="DIV")
			{
				instmem.push_back("000100");
				numArgs=3;
			}
			else if (tempstring== "LW")
			{
				instmem.push_back("100001");
				numArgs=2;
			}
			else if (tempstring =="SW")
			{
				instmem.push_back("100010");
				numArgs=2;
			}
			else if (tempstring== "JMP")
			{
				instmem.push_back("100011");
				numArgs=1;
			}
			else if (tempstring== "BEQ")
			{
				instmem.push_back("100100");
				numArgs=3;
			}
			else if (tempstring== "OR")
			{
				instmem.push_back("000101");
				numArgs=3;
			}
			else if (tempstring=="AND")
			{
				instmem.push_back("000110");
				numArgs=3;
			}
			else
			{
				numArgs=0;
				cout<<"Error reading file."<<endl;
			}
			for(int i=0; i<numArgs; i++)
			{
				file>>tempstring;
				if(tempstring[0]=='R'||tempstring[0]=='D')
					tempstring[0]='0';
				tempInt=atoi(tempstring.c_str());
				instmem.back()+=intToBinary(tempInt);
			}
			while(instmem.back().length()<32)
				instmem.back()+='0';
			string temp1 = instmem.back();
			theFrame->OnImLoadDecode(temp1);
			//cout<<"Instmem: "<<instmem.back()<<endl;
		}
		file.close();
	};
	friend class ControlUnit;
	friend class MainFrame;
};


Yes, I have included #include "mainframe.h" into the InstructionMemory class, but I am getting the following error for some reason:

1
2
3
4
5
6
7
8
9
10
11
main.cpp
1>c:\users\kraigballa\documents\visual studio 2010\projects\form builder\im.h(40) : error C2061: syntax error : identifier 'MainFrame'
1>c:\users\kraigballa\documents\visual studio 2010\projects\form builder\im.h(115) : error C2065: 'theFrame' : undeclared identifier
1>c:\users\kraigballa\documents\visual studio 2010\projects\form builder\im.h(115) : error C2227: left of '->OnImLoadDecode' must point to class/struct/union/generic type
1>        type is ''unknown-type''
1>mainframe.cpp
1>c:\users\kraigballa\documents\visual studio 2010\projects\form builder\im.h(40) : error C2061: syntax error : identifier 'MainFrame'
1>c:\users\kraigballa\documents\visual studio 2010\projects\form builder\im.h(115) : error C2065: 'theFrame' : undeclared identifier
1>c:\users\kraigballa\documents\visual studio 2010\projects\form builder\im.h(115) : error C2227: left of '->OnImLoadDecode' must point to class/struct/union/generic type
1>        type is ''unknown-type''
1>.\mainframe.cpp(70) : error C2660: 'InstructionMemory::decode' : function does not take 2 arguments


Even though decode is setup for two parameters I am still getting the above error. Here is the command from mainframe.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void MainFrame::OnImLoad( wxCommandEvent& event )
{
	m_listBox41->Select(m_listBox41->Append("Load Instructions to instruction array"));
	OnImLoad2();
}

void MainFrame::OnImLoad2()
{
	this->im.decode("TextFile1.txt", *this);
	this->dm.decode("TextFile2.txt");
	this->cu.initialize(this->dm,this->reg,this->cu,this->im,this->alu);
}
void MainFrame::OnImLoadDecode( const wxString &string )
{
	m_listBox3->Select(m_listBox3->Append(string));	
}


I don't understand why this is not working..it seems like the frame object is not being passed correctly. I have looked around and '*this' is the frame object...so it should work. Any ideas?
Last edited on
mainframe.h includes im.h
im.h includes mainframe.h

In im.h you only use pointers to mainframe. So just forward declare class Mainframe; on the top
You need headers guards too.
http://cplusplus.com/forum/articles/10627/ (3 to 7)

Don't using on headers. (it'll corrupt everything that follows)
Topic archived. No new replies allowed.