Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > [Linker error] undefined reference to `CGI::query'

Reply
Thread Tools

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

 
 
Oliver Bleckmann
Guest
Posts: n/a
 
      11-29-2006
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()
{
}
};


 
Reply With Quote
 
 
 
 
Rud1ger Sch1erz
Guest
Posts: n/a
 
      11-30-2006
"Oliver Bleckmann" <Oliver-> writes:

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
typeof x == 'undefined' or x == undefined? -Lost Javascript 13 01-31-2007 12:04 AM
undefined vs. undefined (was: new Array() vs []) VK Javascript 45 09-12-2006 05:26 PM
'Undefined' Client-Side Object Reference Felipe ASP .Net 3 07-16-2004 04:01 AM
undefined behavior or not undefined behavior? That is the question Mantorok Redgormor C Programming 70 02-17-2004 02:46 PM
Error: 'undefined reference' in g++ but gcc succeeded Lu C++ 1 07-10-2003 12:55 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57