F
Fei Liu
Hello, I am getting something really wierd out of this source code, can
you please verify if you also get segmentation fault (memory failure)?
http_form.h: (sorry about the line wrapping, email client problem)
#ifndef HTTP_FORM_H
#define HTTP_FORM_H
#include <map>
#include <string>
#include <iostream>
namespace feiliu{
template <typename value_type>
class http_form{
public:
http_form();
~http_form();
void add_entry(const std:air<std::string, value_type> &
entry){
entries.insert(entry);
}
void add_entry(const std::string & key, const value_type &
value){
entries.insert(std:air<std::string, value_type>(key,
value));
}
std::string get_form_data();
private:
std::map<std::string, value_type> entries;
};
template <typename value_type>
std::string http_form<value_type>::get_form_data(){
typename std::map<std::string, value_type>::iterator iter =
entries.begin();
std::cout << "size of map: " << entries.size() << '\n';
for(int i = 0; i < entries.size(); i ++){
std::cout << "key = " << iter->first << " value = " <<
iter->second << '\n';
++ iter;
}
for(iter = entries.begin(); iter != entries.end(); ++ iter)
std::cout << "key = " << iter->first << " value = " <<
iter->second << '\n';
}
}
#endif
http_form.cpp:
#include "http_form.h"
template <typename value_type>
feiliu::http_form<value_type>::http_form(){
}
//std::string http_form::get_form_data(){
template <typename value_type>
feiliu::http_form<value_type>::~http_form(){
entries.clear();
}
#ifdef TEST_HTTP_FORM
using std::string;
int main(){
feiliu::http_form<string> form;
form.add_entry("hello", "world");
form.add_entry("foo", "bar");
form.get_form_data();
}
#endif
compile: g++ -DTEST_HTTP_FORM -g -O0 -o tf http_form.cpp
run: ./tf
size of map: 2
key = foo value = bar
key = hello value = world
key = foo value = bar
key = hello value = world
Segmentation fault
Apparently, there is something wrong with iterator using begin() and
end()...Any help is appreciated. Thanks,
Fei
you please verify if you also get segmentation fault (memory failure)?
http_form.h: (sorry about the line wrapping, email client problem)
#ifndef HTTP_FORM_H
#define HTTP_FORM_H
#include <map>
#include <string>
#include <iostream>
namespace feiliu{
template <typename value_type>
class http_form{
public:
http_form();
~http_form();
void add_entry(const std:air<std::string, value_type> &
entry){
entries.insert(entry);
}
void add_entry(const std::string & key, const value_type &
value){
entries.insert(std:air<std::string, value_type>(key,
value));
}
std::string get_form_data();
private:
std::map<std::string, value_type> entries;
};
template <typename value_type>
std::string http_form<value_type>::get_form_data(){
typename std::map<std::string, value_type>::iterator iter =
entries.begin();
std::cout << "size of map: " << entries.size() << '\n';
for(int i = 0; i < entries.size(); i ++){
std::cout << "key = " << iter->first << " value = " <<
iter->second << '\n';
++ iter;
}
for(iter = entries.begin(); iter != entries.end(); ++ iter)
std::cout << "key = " << iter->first << " value = " <<
iter->second << '\n';
}
}
#endif
http_form.cpp:
#include "http_form.h"
template <typename value_type>
feiliu::http_form<value_type>::http_form(){
}
//std::string http_form::get_form_data(){
template <typename value_type>
feiliu::http_form<value_type>::~http_form(){
entries.clear();
}
#ifdef TEST_HTTP_FORM
using std::string;
int main(){
feiliu::http_form<string> form;
form.add_entry("hello", "world");
form.add_entry("foo", "bar");
form.get_form_data();
}
#endif
compile: g++ -DTEST_HTTP_FORM -g -O0 -o tf http_form.cpp
run: ./tf
size of map: 2
key = foo value = bar
key = hello value = world
key = foo value = bar
key = hello value = world
Segmentation fault
Apparently, there is something wrong with iterator using begin() and
end()...Any help is appreciated. Thanks,
Fei