Const issues

Hi folks!
How can i amend following code, to make Input function work in this context.
It works well from main function, but i would want to make it accessible from "file with functions";

Second question is about array from main and its accessibility. I will formulate the question a bit later

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <string>
#include <array>

class Hugeinteger
{
public:

static const size_t arraySize = 40; 


Hugeinteger( std::array< int, arraySize > & );


void Input () ;
void Output () const;
void Chooser () const;

private:

std::array< int, arraySize > digits; 
}; 



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
#include <iostream>
#include <iomanip>
#include "Hugeinteger.h" 
	
using namespace std;

	static int counterX;
	Hugeinteger::Hugeinteger( array< int, arraySize > &digitsArray )
	: digits( digitsArray )
	{
	} 

	void Hugeinteger::Input () 

	{

	int key;
	cout << "Entering Input" << endl;
	cin >> key;
	digits[counterX] = key;

	counterX++;
	
	}

	void Hugeinteger::Output () const

	{

	cout << "Entering Output" << endl;
	for (size_t i = 0; i < arraySize; i++)
	cout << digits[i] << endl;

	}

	void Hugeinteger::Chooser () const
     {
	int key;
	while (key !=-1)
	{
	cout << "counterX = \n" << counterX << endl;
	cout << "Choose Operation\n" << endl;
	cout << "[1] to input data" << endl;
	cout << "[2] to output data" << endl;
	cout << "[3] to compare data" << endl;
	cout << "[4] to input data" << endl;
	cin >> key;
	switch(key)
	{
	case 1:
	Input();
	break;
	case 2:
	Output();
	break;
	}

	}
     }





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <array>
#include "Hugeinteger.h" 

using namespace std;

int main()
 
 {

 array< int, Hugeinteger::arraySize > digits =
 
 {87, 68, 94, 100, 83, 78, 85, 91, 76, 87,33,22,12,44,2,2,2,2,2,2,21,3,4,3,2,2,4,2,3,2,42,6,3,4,5,2,1,77,213,34};

 Hugeinteger obj1(digits);
 obj1.Chooser();
 obj1.Input();

 } // end main 
Just Deleted const qualifiers from three functions from header, it works!
Please don't close topic. I will post one question soon.
Namaste
Last edited on
Topic archived. No new replies allowed.