Getting multdimensional array as input and returning a const unsigned char as output

Hi,

I am trying to create a class to get the input as multidimensional array from another class as color[] width[] height[] and create an output as unsigned char[....] Till now I have done this but the console gets stuck when I give the input values... It would be great to know if there is a way to get input as three dimensional array and create an output as single dimension....

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
#include <iostream>
#include<fstream>
#include<stdlib.h>
#include<vector>
//#include "E:\Marvin_To_UnsignedChar\MetisImg.hpp"
//#include "C:\Users\padmanab\Documents\Visual Studio 2013\Projects\Marvin_To_UnsignedChar\MetisImg.hpp"
extern "C"
{
#include "C:\Users\padmanab\Desktop\Marvin_To_UnsignedChar\multiplyImage\multiplyImage.h"
//#include "C:\Users\padmanab\Documents\Visual Studio 2013\Projects\Marvin_To_UnsignedChar\multiplyImage\multiplyImage.h"
}

using namespace std;

class Marvin_To_UnsignedChar
{
public:
	int Color; 
	int Width; 
	int Height;
	std::vector<unsigned char> values;
	Marvin_To_UnsignedChar(int c, int w, int h) : Color(c), Width(w), Height(h), values(c*w*h){}
	unsigned char operator()(int color, int width, int height) const
	{
		return values[Height*Width*color + Height*width + height];
	}
	unsigned char& operator()(int color, int width, int height) 
	{
		return values[Height*Width*color + Height*width + height];
	}
}


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
Main function:

#include "Marvin_To_UnsignedChar.h"
#include <iostream>
#include<fstream>
#include<stdlib.h>
//#include "C:\Users\padmanab\Desktop\Marvin_To_UnsignedChar\multiplyImage\multiplyImage.h"


int main()
{
	/*Marvin_To_UnsignedChar M_To_V;
	unsigned char MM;
	unsigned char MM_2;
	std::string str;
	int color; int width; int height;
	std::cout << "Please enter the color value";
	std::cin >> color;
	M_To_V.Set_Color(&color);
	std::cout << "Please enter the width value";
	std::cin >> width;
	M_To_V.Set_Width(&width);
	std::cout << "Please enter the height value";
	std::cin >> height;
	M_To_V.Set_Height(&height);
	M_To_V.Set_Image_Parameters(&color, &width, &height);
	std::cout << color << width << height;
	std::cout << "\n Image parameters: " <<M_To_V.Get_Image_Parameters() << "\n";
	MM = M_To_V.Convert_To_Unsigned_Char();
	const unsigned char MM_Cast = (const unsigned char)MM;
	MM_2 = multiplyImage(&MM_Cast, 5, &MM);
	//std::cout << "Multiplied image in unsigned char:"  << MM_2;
	return 0;*/
	int color; int width; int height;
	std::cout << "Please enter the color value";
	std::cin >> color;
	std::cout << "Please enter the width value";
	std::cin >> width;
	std::cout << "Please enter the height value";
	std::cin >> height;


	Marvin_To_UnsignedChar M_To_V(color,width,height);
	double test = M_To_V(color, width, height);
	std::cout << test << '\n';


}



Error:

Problem signature: Problem Event Name: APPCRASH Application Name: Marvin_To_UnsignedChar.exe Application Version: 0.0.0.0 Application Timestamp: 53848d56 Fault Module Name: Marvin_To_UnsignedChar.exe Fault Module Version: 0.0.0.0 Fault Module Timestamp: 53848d56 Exception Code: c0000005 Exception Offset: 0000139a OS Version: 6.1.7601.2.1.0.256.48 Locale ID: 1033 Additional Information 1: 0a9e Additional Information 2: 0a9e372d3b4ad19135b953a78882e789 Additional Information 3: 0a9e Additional Information 4: 0a9e372d3b4ad19135b953a78882e789


Last edited on
dont manipulate vector by index [] the way you do - it is unsafe and error prone ( like c0000005).
create structure:
1
2
3
4
5
6
struct some_name_t
{
int color;
int width;
int height;
};


and then put it in they vector, like:
std::vector <some_name_t>
Topic archived. No new replies allowed.