[Linker error] undefined reference to `CGI::query'

O

Oliver Bleckmann

Damn, what's wrong here?

CGI cgi;
map<string,string> cgiParam = cgi.analyseCgiParam();
cout << cgiParam["plz1"] << endl;
cout << cgiParam["vorname1"] << endl;

///////////////////////

#include <iostream>
#include <string>
#include <list>
#include <map>
#include <sstream>
using namespace std;

class CGI
{
private:
static std::string query;
char* input;
const char **names;
const char **values;
int number;
int val;
protected:
public:
list<string> split(string str, char tr)
{
list<string> strElemente; // Ergebnis: Liste von Teilstrings
string::iterator pos1, // Anfang/Ende von
pos2; // Teilstrings
pos1 = str.begin(); // Beginn eines Teilstrings
pos2 = find (pos1, str.end(), tr); // Ende eines Teilstrings
while ( pos2 != str.end())
{
// Trenner als Ende gefunden
assert(*pos2==tr);
string elem; // Teilstring
copy (pos1, pos2, back_inserter(elem)); // Teilstring kopieren
strElemente.push_back(elem); // Teilstring speichern
pos1 = pos2;
++pos1; // neuer Anfang hinter altem Ende
pos2 = find (pos1, str.end(), tr); // neue Suche
}
// pos2 zeigt auf das Ende. pos1 zeigt auf den Beginn
// des letzten Teilstrings vor dem Ende.
// Letzten Teilstring extrahieren:
//
string last;
copy (pos1, str.end(), back_inserter(last));
strElemente.push_back(last);
return strElemente;
}
map<string, string> analyseCgiParam()
{
std::string meth_s = null_to_empty(std::getenv("REQUEST_METHOD"));
if (meth_s == "")
{
cout << "EMPTY" << endl;
}
else if (meth_s == "GET")
{
query = null_to_empty(getenv("QUERY_STRING"));
cout << "GET" << endl;
cout << query << endl;
}
else if (meth_s == "POST")
{
int len = atoi(getenv("CONTENT_LENGTH"));
// MIME getenv("CONTENT_TYPE") application/x-www-form-urlencoded
//std::string input[len+1];
input = new char[len+1];
fread(input, 1, len, stdin);
input[len] = 0;
cout << "POST" << endl;
query = input;
cout << query << endl;
delete input;
//fflush ( stdin );
}
else cout << "NONE" << endl;
list<string> feldListe = split(query, '&'); // in Felder zerlegen
map<string,string> felder; // Ergebnis
// Felder in Paare aus Feldnamen und Wert splitten
for ( list<string>::iterator i = feldListe.begin(); i !=
feldListe.end(); ++i)
{
list<string> feldStr = split(*i, '=');
pair< string, string > feld;
feld.first = feldStr.front(); // Feldname
feldStr.pop_front();
feld.second = feldStr.front(); // Feldwert
felder[feld.first] = feld.second; // Paar speichern
}
return felder; // Abbildung Feld-Name -> Feld-Wert zurueck geben
}
inline const char * null_to_empty(const char * str)
{
if (! str)
return "";
return str;
}
int string2Int(string str)
{
istringstream istr (str);
int i;
istr >> i;
return i;
}
CGI()
{
}
virtual ~CGI()
{
}
};
 
R

Rud1ger Sch1erz

Oliver Bleckmann said:
Damn, what's wrong here?

CGI cgi;
map<string,string> cgiParam = cgi.analyseCgiParam();
cout << cgiParam["plz1"] << endl;
cout << cgiParam["vorname1"] << endl;

///////////////////////

#include <iostream>
#include <string>
#include <list>
#include <map>
#include <sstream>
using namespace std;

class CGI
{
private:
static std::string query;
^^^^
Here you declare a static variable. Somewhere in your program in a
compile unit you must also define and initialize it, like a global
variable.

[snipped rest of posted code]

somewhere in a .cc:

std::string CGI::query = "";

HTH,
Rudiger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top