I cannot find where this problem is coming from and it is driving me insane! My main and a pastebin link are below. I keep getting this error:
First-chance exception at 0x0FFE108E (msvcr110d.dll) in MasterMindFSM.exe: 0xC0000005: Access violation reading location 0x2CF0D131.
Unhandled exception at 0x0FFE108E (msvcr110d.dll) in MasterMindFSM.exe: 0xC0000005: Access violation reading location 0x2CF0D131.
Here is my main:
#pragma once
#include <iostream>
#include "Answer.hpp"
using namespace Games::MasterMind;
int main() {
Answer Line;
std::cout << Line.getAnswer(0) << std::endl;
std::cout << Line.getAnswer(1) << std::endl;
std::cout << Line.getAnswer(2) << std::endl;
std::cout << Line.getAnswer(3) << std::endl;
system("pause");
return 0;
}
Here is the header file that accompanies main:
(Sorry, but it lost it’s formatting)
Q: What is “Line”?
Q: Does it’s constructor allocate an Answer(0), Answer(1), Answer(2), …?
Failure to allocate an entity before you use it can easily cause a segmentation violation 😉
======================================
I just looked at your (cleverly hidden ;)) “Answer.hpp”.
PROBLEM:
1) “getAnswer()” looks perfectly OK (I thought that’s where you were having problems)
2) The actual problem is in “setAnswer()” – you’re running off the end of your array!