2011-06-15 70 views
1

我在使用fastcgi ++ 2 beta会话时遇到问题。与fastcgi ++使用会话

这里是我的代码:

#include <fastcgi++/http.hpp> 
#include <fastcgi++/request.hpp> 
#include <fastcgi++/manager.hpp> 
#include <string> 

using namespace std; 
using namespace Fastcgipp::Http; 

class SessionsPage : public Fastcgipp::Request<char> { 
    static Sessions<string> sessions; 
    Sessions<string>::iterator session; 

    bool response() { 
     sessions.cleanup(); 

     out << "Content-Type: text/html;\r\n\r\n"; 
     out << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" << std::endl; 
     out << "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\" >" << std::endl; 
     out << " <head>" << std::endl; 
     out << "  <title>Sessions</title>" << std::endl; 
     out << "  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" << std::endl; 
     out << " </head>" << std::endl; 
     out << " <body>" << std::endl; 
     out << "  <p>Hello World!</p>" << std::endl; 
     out << " </body>" << std::endl; 
     out << "</html>" << std::endl; 
     return true; 
    } 
}; 

int main() { 
    Fastcgipp::Manager<SessionsPage> fcgi; 
    fcgi.handler(); 
} 

我得到了以下错误:

/tmp/ccRujo45.o: In function `SessionsPage::response()': 
sessions_page.cpp:(.text._ZN12SessionsPage8responseEv[SessionsPage::response()]+0xd): undefined reference to `SessionsPage::sessions' 
collect2: ld a retourné 1 code d'état d'exécution 

如果我评论这条线,它编译:

sessions.cleanup(); 

我使用this tutorial

感谢您的帮助。

回答

1

static Sessions<string> sessions;只在类中声明;你需要为它创建一个定义。在这种情况下,我相信在你的课没有问题之后坚持Sessions<string> SessionsPage::sessions;,因为这个课只用于一个翻译单元。 (如果在多个翻译单元中使用它,则必须在一个中定义静态变量,并且只有一个翻译单元)

+0

您是对的。我在课后添加了这个:Sessions SessionsPage :: sessions(30,30); – antoyo 2011-06-16 21:30:03