GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Oct-2004, 09:44
bucho bucho is offline
New Member
 
Join Date: Oct 2004
Posts: 2
bucho is on a distinguished road

help with classes


I'm making a simple gui, that loads in to matrices from files located on "a:" and I'm making my own simple matrix class and matrix math class, everything looks correct to me and even thou I include the header file for the math and matrix class to the gui class it always says these errors: it was created using MFC and the MFC Application wizard with Use MFC in a Shared DLL.
Thanks for any help!

error C2061: syntax error : identifier 'ropaMatrix'
syntax error : missing ';' before identifier 'matrixA'
error C2501: 'CpayneMatDlg::ropaMatrix' : missing storage-class or type specifiers
error C2501: 'CpayneMatDlg::matrixA' : missing storage-class or type specifiers
code:
CPP / C++ / C Code:
// payneMatDlg.cpp : implementation file

#include <iostream>
#include <string>
#include <fstream.h>
#include "calculate.h"
#include "stdafx.h"
#include "payneMat.h"
#include "payneMatDlg.h"
#include ".\paynematdlg.h"
#include "rpayneMatrix.h"
#include <string>
#include <sstream>
#include <fstream>
#include <stdlib.h>

using namespace std;



// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	
	
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


// CpayneMatDlg dialog



CpayneMatDlg::CpayneMatDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CpayneMatDlg::IDD, pParent)
	, operations(0)
	, m(0)
	
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	
}

void CpayneMatDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, m);
	DDV_MinMaxInt(pDX, m, 0, 10);
	//{{AFX_DATA_MAP(CGuiDlg)
	DDX_Radio(pDX, IDC_RADIO1, operations);

	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CpayneMatDlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_EN_CHANGE(IDC_EDIT1, OnEnChangeEdit1)
	ON_BN_CLICKED(IDC_RADIO1, OnBnClickedRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnBnClickedRadio2)
	ON_BN_CLICKED(IDC_RADIO3, OnBnClickedRadio3)
	ON_BN_CLICKED(IDC_RADIO4, OnBnClickedRadio4)
	ON_BN_CLICKED(IDC_RADIO5, OnBnClickedRadio5)
	ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
END_MESSAGE_MAP()


// CpayneMatDlg message handlers

BOOL CpayneMatDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CpayneMatDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CpayneMatDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CpayneMatDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

void CpayneMatDlg::OnEnChangeEdit1()
{

}



void CpayneMatDlg::OnBnClickedRadio1()
{
	if (UpdateData(TRUE))
	{
		calc.add(matrixA,matrixB);
		UpdateData(FALSE);		
		Invalidate();
		
	}
}

void CpayneMatDlg::OnBnClickedRadio2()
{
	if (UpdateData(TRUE))
	{
		calc.subtract(matrixA,matrixB);
		UpdateData(FALSE);		
		Invalidate();
		
	}
}

void CpayneMatDlg::OnBnClickedRadio3()
{
	if (UpdateData(TRUE))
	{
		calc.multiply(matrixA,matrixB);
		UpdateData(FALSE);		
		Invalidate();
		
	}
}

void CpayneMatDlg::OnBnClickedRadio4()
{
	if (UpdateData(TRUE))
	{
		calc.transpose(matrixA);
		UpdateData(FALSE);		
		Invalidate();
		
	}
}

void CpayneMatDlg::OnBnClickedRadio5()
{
	if (UpdateData(TRUE))
	{
		calc.transposeB(matrixB);
		UpdateData(FALSE);		
		Invalidate();
		
	}
}


void CpayneMatDlg::OnBnClickedButton1()
{
	//Loading the matrix 1 from a file
	if (UpdateData(TRUE))
	{
		matrixA.loadMatrix(m);
		UpdateData(FALSE);		
		Invalidate();
		
	}
}

void CpayneMatDlg::OnBnClickedButton2()
{
//Loading the matrix 2 from a file
	if (UpdateData(TRUE))
	{
		matrixB.loadMatrixB(m);
		UpdateData(FALSE);		
		Invalidate();
		
	}
}


CPP / C++ / C Code:
// payneMatDlg.h : header file
//

#pragma once
#include "ropaMatrix.h"
#include <iostream>
#include <string>
#include "matrixMath.h"
#include "stdafx.h"
#include "payneMat.h"
//#include "payneMatDlg.h"
#include ".\paynematdlg.h"
#include <string>
#include <sstream>
#include <fstream>
#include <stdlib.h>
using namespace std;


// CpayneMatDlg dialog
class CpayneMatDlg : public CDialog
{
// Construction
public:
	CpayneMatDlg(CWnd* pParent = NULL);	// standard constructor
	int operations;
	int m;
	ropaMatrix matrixA;
	ropaMatrix matrixB;
	matrixMath calc;

// Dialog Data
	enum { IDD = IDD_PAYNEMAT_DIALOG };

// Implementation
protected:
	virtual void DoDataExchange(CDataExchange* pDX);
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnEnChangeEdit1();
	afx_msg void OnBnClickedRadio1();
	afx_msg void OnBnClickedRadio2();
	afx_msg void OnBnClickedRadio3();
	afx_msg void OnBnClickedRadio4();
	afx_msg void OnBnClickedRadio5();
	afx_msg void OnBnClickedButton1();
	afx_msg void OnBnClickedButton2();
	DECLARE_MESSAGE_MAP()
		


	
};

CPP / C++ / C Code:
#pragma once
#include <fstream>
#include <sstream>
#include <fstream>
#include <stdlib.h>
#include <iostream>
#include ".\ropaMatrix.h"

using namespace std;

class matrixMath
{
public:
	matrixMath(void);
	~matrixMath(void);
	ofstream matfile;
	int rslt[10][10];
	void add(ropaMatrix matA, ropaMatrix matB);
	void subtract(ropaMatrix matA, ropaMatrix matB);
	void multiply(ropaMatrix matA, ropaMatrix matB);
	void transposeA(ropaMatrix matA);
	void transposeB(ropaMatrix matB);
};

CPP / C++ / C Code:
#include "StdAfx.h"
#include ".\matrixmath.h"
#include "ropaMatrix.h"
matrixMath::matrixMath(void)
{
}

matrixMath::~matrixMath(void)
{
}

void matrixMath::add(ropaMatrix matA, ropaMatrix matB)
{
	//UpdateData();
	for(int row =0; row < matB.getSize(); row++)
		for(int col =0;col < matB.getSize(); col++)
			rslt[row][col]= matA.getValue(row,col) + matB.getValue(row,col);
			
			matfile.open("a:\\addm.txt", ios::out); 
			for(int row = 0; row < matB.getSize(); row++){
				for(int col = 0; col < matB.getSize(); col++)
						matfile << rslt[row][col] <<" ";
				matfile <<endl;
			}
			matfile.close();
		//	UpdateData(FALSE);
}

void matrixMath::subtract(ropaMatrix matA, ropaMatrix matB)
{
//	UpdateData();
	for(int row = 0; row < matB.getSize(); row++)
				for(int col =0;col < matB.getSize(); col++)
					rslt[row][col] = matA.getValue(row,col) - matB.getValue(row,col);
			matfile.open("a:\\subm.txt", ios::out); 
			for(int row = 0; row < matB.getSize(); row++){
				for(int col = 0; col < matB.getSize(); col++)
					matfile << rslt[row][col]<<" ";
			matfile <<endl;
			}
			matfile.close();
		//	UpdateData(FALSE);
}

void matrixMath::multiply(ropaMatrix matA, ropaMatrix matB)
{
	//UpdateData();
	for(int row = 0; row < matB.getSize(); row++){
				for(int col = 0 ;col < matB.getSize(); col++){
					rslt[row][col] =0 ;
					for(int n = 0; n < matB.getSize(); n++)
                        rslt[row][col]+= matA.getValue(n,row) * matB.getValue(col,n);
				}
			}
			matfile.open("a:\\multm.txt", ios::out); 
			for(int row = 0; row < matB.getSize(); row++){
				for(int col = 0; col < matB.getSize(); col++)
					matfile << rslt[row][col] <<" ";
					matfile <<endl;
				}
			matfile.close();
	//		UpdateData(FALSE);
}

void matrixMath::transposeA(ropaMatrix matA)
{
//	UpdateData();
	for( int row = 0; row <  matA.getSize(); row++)
				for(int col =0; col <  matA.size; col++)
					rslt[row][col]= matA.getValue(col,row);

			matfile.open("a:\\transa.txt", ios::out); 
			for(int row = 0; row < matA.getSize(); row++){
				for(int col = 0; col < matA.getSize(); col++)
					matfile << rslt[row][col] <<" ";
					matfile <<endl;
				}
			matfile.close();
	//		UpdateData(FALSE);
}

void matrixMath::transposeB(ropaMatrix matB)
{
	//UpdateData();
	for(int row =0;row < matB.getSize(); row++)
		for(int col =0;col < matB.getSize(); col++)
			rslt[row][col]= matB.getValue(row,col);
			
	matfile.open("a:\\transb.txt", ios::out); 
	for(int row = 0; row < matB.getSize(); row++){
			for(int col = 0; col < matB.getSize(); col++)
				matfile << rslt[row][col] <<" ";
				matfile <<endl;
				}
	matfile.close();
//	UpdateData(FALSE);
}

CPP / C++ / C Code:
#pragma once
#include "payneMatDlg.h"
class ropaMatrix
{
public:
	ropaMatrix(void);
	~ropaMatrix(void);
	int size;
	int matrixPayne[10][10];
	int getValue(int Rindex, int Cindex);
	int getSize(void);
	void loadA(int matSize);
	void loadB(int matSize);
	void zeros(void);
	
};

CPP / C++ / C Code:
#include "StdAfx.h"
#include ".\ropamatrix.h"

ropaMatrix::ropaMatrix(void)
{
}

ropaMatrix::~ropaMatrix(void)
{
}

int ropaMatrix::getValue(int Rindex, int Cindex)
{
	return matrixPayne[Rindex][Cindex];
}

int ropaMatrix::getSize(void)
{
	return size;
}

void ropaMatrix::loadA(int matSize)
{
	size = matSize;
	zeros();
	ifstream matfile;
		matfile.open("a:\\test1.txt", ios::in); 
		for(int row = 0; row < size; row++)
			for(int col = 0; col < size; col++)
					matfile >> matrixPayne[row][col];
		matfile.close();
	
}

void ropaMatrix::loadB(int matSize)
{
	size = matSize;
	zeros();
	ifstream matfile;
		matfile.open("a:\\test2.txt", ios::in); 
		for(int row = 0; row < size; row++)
			for(int col = 0; col < size; col++)
					matfile >> matrixPayne[row][col];
		matfile.close();
}

void ropaMatrix::zeros(void)
{
	for(int i =0; i < size; i++)
		for(int j = 0; j < size; j++)
			matrixPayne[i][j] = 0;
}
  #2  
Old 18-Oct-2004, 07:01
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,037
LuciWiz is just really niceLuciWiz is just really niceLuciWiz is just really niceLuciWiz is just really nice
Well, sometimes you have

CPP / C++ / C Code:
#include ".\ropamatrix.h"

and, sometimes:

CPP / C++ / C Code:
#include "ropaMatrix.h"

Is this correct? I mean it might be, but I don't know how your project is set up....
Interesting enough that in payneMatDlg.h you have the "second" version of include:

CPP / C++ / C Code:
// payneMatDlg.h : header file
//

#pragma once
#include "ropaMatrix.h"
#include <iostream>
#include <string>
#include "matrixMath.h"
#include "stdafx.h"
#include "payneMat.h"
//#include "payneMatDlg.h"
#include ".\paynematdlg.h"
#include <string>
#include <sstream>
#include <fstream>
#include <stdlib.h>
using namespace std;


// CpayneMatDlg dialog
class CpayneMatDlg : public CDialog
{
// Construction
public:
  CpayneMatDlg(CWnd* pParent = NULL);  // standard constructor
  int operations;
  int m;
  ropaMatrix matrixA;
  ropaMatrix matrixB;
  matrixMath calc;
//....

Maybe it doesn't find your definition for the clas??
If this isn't it (I need confirmation), I'll take another look on your code. If this is the case, please supply the structure of your project: Folder | File.

Kind regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #3  
Old 18-Oct-2004, 09:42
bucho bucho is offline
New Member
 
Join Date: Oct 2004
Posts: 2
bucho is on a distinguished road
I figured out what I was doing wrong, I was careless and I name my class functions with no capital letter at the begining and it didn't like that.
Thanks for trying to help
  #4  
Old 20-Oct-2004, 06:16
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,037
LuciWiz is just really niceLuciWiz is just really niceLuciWiz is just really niceLuciWiz is just really nice
Quote:
Originally Posted by bucho
I figured out what I was doing wrong, I was careless and I name my class functions with no capital letter at the begining and it didn't like that.
Thanks for trying to help

Huh?
We probably don't understand each other... Do you mean you named your functions differently in your header than in your implementation file? That would make sense.

I hope you don't mean the thing I first thought you do If you are using VC++ (I guess you are since you are posting on this forum) than you CAN name your methods with capital letters or without. You just need to be consistent.

Example:


testGID.cpp

CPP / C++ / C Code:
// testGID.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "conio.h"
#include "testClass.h"

int main(int argc, char* argv[])
{
	test * wow = new test();
	wow->testing();
	getch();
	return 0;
}



testClass.cpp

CPP / C++ / C Code:
#include "stdafx.h"
#include "testClass.h"
#include "iostream.h"

void test::testing()
{
	cout << "Nothing wrong here" << endl;
}



testClass.h

CPP / C++ / C Code:
class test
{

public:
	void testing();
};

This sample will run on VC 6, and I don't use capitalized first letters on methods!!

I am actually almost certain I missunderstood your post and this was not actually what you were saying.... Just wanted to make sure nobody else does the same

Best regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
 
 

Recent GIDBlogRunning Linux Programs at Boot Time by gidnetwork

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
First time using classes crystalattice C++ Forum 6 13-Oct-2004 08:21
SDL + Classes Question darkzerox C++ Forum 2 23-May-2004 19:38
ClassView not showing my classes (VC++, namespace, headers) ?!?!? djovanov C++ Forum 1 13-Jan-2004 04:54
using windows WMI and CMI classes in Dev-c++ Dawis C++ Forum 0 26-Oct-2003 04:18
Issue with preg_replace, e modifier inside PHP classes JdS MySQL / PHP Forum 2 31-May-2003 23:01

Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:01.


vBulletin, Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.