Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
I have recently migrated from g++ to Visual C++.
I have this code that compiled without any errors or warnings under g++, but now in VC++ using VS10 as my IDE, I get an error that reads:
Unhandled exception at 0x70f333bc (msvcp100.dll) in myProgram.exe: 0xC0000005: Access violation reading location 0x00000004.
 
#include <sstream>
#include <iostream>
#include <exception>
class parentClass:virtual public std::exception{
private:
 std::string s1;
 std::string s2;
 std::string s3
 std::string s4;
 std::string Where;
 size_t st;
 
public: 
 std::string& getFile(){return s1;}
 std::string& getMethod(){return s2;}
 std::string& getTitle(){return s3;}
 size_t getLine(){return st;}
 virtual const std::string& what(){return std::exception::what() + "--" + s4;}
 
 std::string& where() throw();
 void displayData(){/*...*/}
};
 
std::string& parentClass::where() throw() {
  Where =  "File: " + getFile() + "\nMethod: " + getMethod();
 
  std::stringstream num; //<== RunTime Error
  num.flush();
  num << getLine();
  Where += "\nLine ";
  Where += num.str();
 
  return Where;
}
 
class childClass : virtual public parentClass{
private:
  std::wstring msg;
  std::wstring title;
public: 
  virtual void displayData();
};
void childClass::displayData(){
  std::string s = what() + "\n" + where();
  std::string t = getTitle();
  
  title = std::wstring(t.begin(), t.end());
  msg = std::wstring(s.begin(), s.end());
 
  int msgboxID = MessageBox(NULL,msg.c_str(),title.c_str(),MB_ICONHAND | MB_OK);
}
Posted 24-Jan-13 18:44pm
Edited 24-Jan-13 18:46pm
v2
Comments
Sergey Alexandrovich Kryukov at 25-Jan-13 0:50am
   
In what line?
—SA
merano at 25-Jan-13 2:06am
   
Codefragment does not compile because no "_mainCRTStartup"
 
Where is the error ?
merano at 25-Jan-13 2:13am
   
virtual const std::string& what(){return std::exception::what() + "--" + s4;}

Does not compile at all. Compiler says "Two Pointer can not be added"
Marius Bancila at 25-Jan-13 8:19am
   
Why are you returning non-const references from getFile/etc. and where()?
 
BTW, displayData() should be declared virtual in the parent.
ArbolOneDotOrg at 25-Jan-13 10:37am
   
I have realized that VS10, for some reason, is not working correctly. I have created a test program using MinGW and Code::Blocks and I don't get any related error, when I went to test the same code with vs10, it reported that it has become corrupted. I will fix VS10, but in the mean time will continue work using C::B. I am sorry, for the inconvenience.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Please add main function to your program.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I have realized that VS10, for some reason, is not working correctly. I have created a test program using MinGW and Code::Blocks and I don't get any related error, when I went to test the same code with vs10, it reported that it has become corrupted. I will fix VS10, but in the mean time will continue work using C::B. I am sorry, for the inconvenience.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100