EXC Bad Access on conversion to string/ access violation

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
#include <iostream>
#include <string>
#include <sstream>
#include <vector>

using namespace std;
int product();
vector<int>splitter(1);


int charToInt(char ch);
template <class T>
string toString(T num);
template <class T>
void printVector(const vector<T>& v);

template <typename T>
void vectorPrint(const vector<T> &list) {
    for (T item : list) {
        cout << item << " ";
    }
}



int charToInt(char ch) {
    return ch - '0';
}

class numbas {
    
private:
    int number{1};
    
    string strin = to_string(number);
    
public:
    
    
    
    
    
    
    Numbas(int num)
    {
        
        if (num < 1) {
            number = 1;
        }
        else{
            number = num;
        }
        vector<int> splitter(10);
        vector<int>sequence(int counter);
    }
    
    int getNumber(){
        return number;
        
    }
    
    void setNumber(int x){
        
        if (x < 0) {
            number = 1;
        }
        else {
            number = x;
        }
    }
  
    vector<int> splitter(){
        
        
        string strin = to_string(number);
        
        for (int i = 0 ; i < strin.length(); i++) {
            
            
            int convert = charToInt(strin[i]);
            
            if (convert > 0){
                splitter().push_back(convert);
            }
            
        }
        
        return splitter();
        
    }
    
};


int main(int argc, const char * argv[]) {
    
    
    vectorPrint(Numbas(23040502).splitter());
    

    
}



I have no idea how to solve this, it keeps throwing the Access Violation writing location 0x01240FFC code at me.
Last edited on
Any help would be greatly appreciated, I've been stuck like this for hours now :'D
After fixing the typos (change the two occurrences of Numbas to numbas),
the microsoft compiler with -W4 -analyze reports:

source_file.cpp(54): warning C4930: 'std::vector<int,std::allocator<_Ty>> sequence(int)': prototyped function not called (was a variable definition intended?)
        with
        [
            _Ty=int
        ]

source_file.cpp(75): warning C4458: declaration of 'strin' hides class member
source_file.cpp(35): note: see declaration of 'numbas::strin'

source_file.cpp(53) : warning C6244: Local declaration of 'splitter' hides previous declaration at line '8' of 'source_file.cpp'.: Lines: 8

source_file.cpp(90) : warning C4717: 'numbas::splitter': recursive on all control paths, function will cause runtime stack overflow

http://rextester.com/MEAI97374
Topic archived. No new replies allowed.