Jump to content
  • Advertisement
Sign in to follow this  
Tradone

strange integar runtime error

This topic is 4583 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

//IfClass.h
#if !defined(IFCLASS)
#define IFCLASS

#include <vector>

class IfClass{
	public:
		IfClass(){};
		void IfPushBack( const int truth ){
			truthTable.push_back( truth );
		};
		void IfPopBack(){
			truthTable.pop_back();
		};
		void IfPushPop(){
			if ( truthTable[ truthTable.size()-2 ] )
				truthTable[ truthTable.size()-1 ] = !truthTable[ truthTable.size() ];
			else
				truthTable[ truthTable.size()-1 ] = 0;
		};
		bool IfCheck(){
			if( truthTable[ truthTable.size()-1 ] )
				return 1;
			return 0;
		};
		void IfPrint(){
			for ( int i=0; i < truthTable.size(); i++ )
				std::cout << truthTable;
		}

	//end public:

	private:
		std::vector<int> truthTable;
	//end private:

};
#endif

// This is what is causing the runtime errors
truthTable.IfPushBack( FunctionEvalIf(para_if) ); 
// This is what is causing the runtime errors

//Below is the FunctionEvalIf(std::string) Function
int Skin::FunctionEvalIf( std::string para_if ){

	return 0;
}


there is no problem!! That's the thing. it seems like when I just perform truthTable.IfPushBack( 1 ); or truthTable.IfPushBack( 0 ); there is no problem, but when I use the values returned from the FunctionEvalIf function, there seems to be a problem.

Share this post


Link to post
Share on other sites
Advertisement
What exactly is the error that is displayed? It looks like you're calling FunctionEvalIf(para_if) from an object called 'truthtable' which is of type 'Skin' but the class definition shown here is IfClass. Is my confusion caused by my admitted lack of experience or is there some problem there?

Share this post


Link to post
Share on other sites
Quote:
Original post by vinb
What exactly is the error that is displayed? It looks like you're calling FunctionEvalIf(para_if) from an object called 'truthtable' which is of type 'Skin' but the class definition shown here is IfClass. Is my confusion caused by my admitted lack of experience or is there some problem there?


there are no errors displayed,
it's a runtime error and is executed on the web.
lemme check the apache log

Share this post


Link to post
Share on other sites
and when I run the application on the command line prompt I get this kind of dumping error

terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct NULL not valid
Abort (core dumped)

it also seems like there is no logs that are being recorded, but it takes about 5 minutes to get an internal server error, i'll check the logs then.

also there is no *.core file to evaulate what's wrong too.

Share this post


Link to post
Share on other sites
and here's a little bit about the Skin Class


//skin.h
#if !defined(SKIN)
#define SKIN

#include "Cookie.h"
#include "Parameter.h"
#include "Path.h"
#include "Config.h"
#include "IfClass.h"
#include "LoopClass.h"

#include <string>
#include <iostream>
#include <map>
#include <iterator>
#include <vector>

//header
class Skin {
private:
bool SaveToString( std::string para_skinIncludes );
void ParseToMap();
void ParseComments();

std::map<std::string,std::string>::const_iterator loop;

//a map with a key of Body, and value pair of with unparsed ($'s
std::map<std::string, std::string> skinType;

//contains the file to be evaluated.
std::vector<std::string> skinIncludes;

//at first this is the file that holds the whole unparsed contents of the skin file
//will later become empty.
std::string unparsedSkinContents;

//a string to temporarily load and hold the value pair of a skinType map.
std::string skinTypeValue;

//a map with positions of ($if flags
IfClass truthTable;
LoopClass loopTable;

void ParseLoops( std::string& para_skinTypeValue);
std::map<std::string,std::string> loopDefinition;

void ParseFunctions( std::string para_skinTypeValue);
void EvaluateFunction( std::string para_evaluate );

void FunctionMenu( std::string para_menu );
void FunctionDB( std::string para_db );
void FunctionCount( std::string para_type );
void FunctionSet( std::string para_set );
void FunctionStrcat( std::string para_strcat );
void FunctionIf( std::string para_if );
void FunctionIfnot( std::string para_ifnot );
int FunctionEvalIf( std::string para_if );
void FunctionColor( std::string para_color );
void FunctionAdd( std::string para_add );
void FunctionMinus( std::string para_minus );
void FunctionLoop( std::string para_number );
void FunctionLink( std::string para_link );
void FunctionHidden( std::string para_info );

//the positioner is used to mark the beginnings and ends when taking out types.
struct {
int Begin;
int End;
} Positioner;

//the holder is used to contain the key and value of what the positioner has provided.
struct {
std::string Key;
std::string Value;
std::string End;
} Holder;

struct {
std::string BeforeEqualBeforeDot;
std::string BeforeEqualAfterDot;
std::string AfterEqualBeforeDot;
std::string AfterEqualAfterDot;
std::string BeforeEqual;
std::string AfterEqual;
} Temp;


Cookie skinCookie;
Parameter skinParameter;
Path skinPath;
Config skinConfig;
//end private:

public:
Skin( const std::string para_skinPath );
Skin( const std::string para_skinPath, Cookie& para_skinCookie, Parameter& para_skinParameter, Path& para_skinPath, Config& para_skinConfig );
void Read( std::string para_string );
//end public:
};

#endif

int FunctionEvalIf( std::string para_if );



void Skin::FunctionIf( std::string para_if ){
truthTable.IfPushBack(1);

truthTable.IfPushBack( FunctionEvalIf(para_if) );
std::cout << "FunctionIf[" << FunctionEvalIf(para_if) << "]";

//truthTable.IfPushBack( FunctionEvalIf(para_if) );
truthTable.IfPrint();




}





int Skin::FunctionEvalIf( std::string para_if ){

std::cout << para_if; // I added this to check if parameters have been passed corrected
return 0;
}














so.. yea..
I think there's no problem!



Share this post


Link to post
Share on other sites
Quote:
Original post by Conner McCloud
vec[vec.size()] is invalid. Don't know if that's your problem, because I'm not sure what your class is doing. But its a good place to start.

CM


wait, why is this invalid?
what alternatives do I have?
and it's vec[vec.size()-1] so that it's going to be the last added vector.
so then should I

int temp_size=vec.size();
vec[temp_size-1];

do something like this?

Share this post


Link to post
Share on other sites
Quote:
Original post by Tradone
wait, why is this invalid?

Vector's are 0-based, so size()-1 is the last valid index.
Quote:
Original post by Tradone
what alternatives do I have?

To get the last element, vec.back() works rather well. To get the second to last element, you do need to either reference size [vec[size()-2] or vec.at(size()-2)], or use iterators [*(vec.rbegin()+1)]. Use whichever makes the most sense to you, just remember those off-by-one errors, and careful that you have at least two elements.

CM

Share this post


Link to post
Share on other sites
so vector.size()-1 is valid right?
hm.. then there seems to be no problem..
by the way, the vector.size() that i used above was an error, what I meant was vector.size()-1, so I changed that.

another note, when I test out the function FunctionEvalIf(std::string)
and when I output the results of that function, I get the currect output,
I just can't pass that output into truthTable.IfPushBack( FunctionEvalIf(para_if) );

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!