|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Subclassing CgiInputHello @All.
I hope anyone can help me on this topic. I'm trying to use the cgicc library in a FastCgi environment. Therefore I want to subclass CgiInput as described in the cgicc documentation. My FastCgiInput class looks as follows: class FastCgiInput : public cgicc::CgiInput { friend class FastCgiManager; private: FastCgiInput(); FastCgiInput(const FastCgiInput & anOriginal); public: virtual ~FastCgiInput(); public: virtual size_t read(char * Data, size_t aLength) const; virtual std::string getenv(const char * aName) const; }; The constructor is private, because only the methods of the friend class FastCgiManager should be able to create FastCgiInput objects. It has no effect, if I change the constructors to be public. However, the behaviour is not the desired one: It is possible to create a new object of type FastCgiInput and the overloaded methods read and getenv work fine, if called directly on the created object. But it is impossible to create an object of type CgiEnvironment by passing a FastCgiInput object to the constructor. If doing so, the CgiEnvironment seems not to be able to read out the environment variables. As an illustration: FastCgiInput * i = new FastCgiInput(); CgiEnvironment * e = new CgiEnvironment(i); A call to i->getenv("QUERY_STRING") is successful and returns the right query string, but a call to e->getQueryString() returns an empty string. The documentation says, that the operator= must be overloaded. What exactly does that mean? What signature should I use when overloading operator=? How does this affect the behaviour of the code? Thanks, Matthias _______________________________________________ help-cgicc mailing list help-cgicc@... http://lists.gnu.org/mailman/listinfo/help-cgicc |
|
|
Re: Subclassing CgiInputOn 2007-04-19T20:49:30+0200, mk.gnu@... wrote:
> FastCgiInput * i = new FastCgiInput(); > CgiEnvironment * e = new CgiEnvironment(i); > > A call to i->getenv("QUERY_STRING") is successful and returns the right query string, but a call to e->getQueryString() returns an empty string. > > The documentation says, that the operator= must be overloaded. What > exactly does that mean? What signature should I use when overloading > operator=? How does this affect the behaviour of the code? It means you have to define: FastCgiInput & operator= (const FastCgiInput &) The default copy constructor is currently called instead. If you have not, just trace the original implementation and do the same with yours and see what happens. /Allan _______________________________________________ help-cgicc mailing list help-cgicc@... http://lists.gnu.org/mailman/listinfo/help-cgicc |
|
|
Re: Subclassing CgiInputThanks for the help!
> On 2007-04-19T20:49:30+0200, mk.gnu@... wrote: > > FastCgiInput * i = new FastCgiInput(); > > CgiEnvironment * e = new CgiEnvironment(i); > > > > A call to i->getenv("QUERY_STRING") is successful and returns the right > query string, but a call to e->getQueryString() returns an empty string. > > > > The documentation says, that the operator= must be overloaded. What > > exactly does that mean? What signature should I use when overloading > > operator=? How does this affect the behaviour of the code? > > It means you have to define: > > FastCgiInput & operator= (const FastCgiInput &) > > The default copy constructor is currently called instead. If you have > not, just trace the original implementation and do the same with yours > and see what happens. > > > /Allan I resolved the problem: As you mentioned above, the default copy constructor is called, if no operator= is present. I tried to implement one, but that didn't change the behaviour. Then I took again a closer look at my FastCgiInput class an saw the problem: I "overloaded" the functions virtual size_t read(char * Data, size_t aLength) const; virtual std::string getenv(const char * aName) const; as described in my first post. But this is not an overloading, because I made this tow functions "const". The right signature to use when overloading this functions must be virtual size_t read(char * Data, size_t aLength); virtual std::string getenv(const char * aName); With this change it works fine. In the current implementation both, the default constructor and the default copy-constructor, are protected and only callable from friend classes. Additionaly I removed the operator= from the implementation and it still works fine. I wondered about the comment in the documentation which says, that operator= must be overloaded, because the source code of my cgicc library shows, that all CgiInput objects are managed by pointers. So there is never a call to operator= or to the default copy constructor during the contruction of Cgicc or CgiEnvironment objects. At least this implementation works now. Thanks to Allan for the help! I hope this post can help anyone to avoid this "trap" when "overloading" functions, because the compiler cannot guess, that this is not what I intended it to be. The only question which is left is: What does the comment "operator= must be overloaded" mean in the documentation? Is it a comment from an older version? Thanks, Matthias _______________________________________________ help-cgicc mailing list help-cgicc@... http://lists.gnu.org/mailman/listinfo/help-cgicc |
|
|
Re: Subclassing CgiInputHello mk,
Thursday, April 19, 2007, 10:49:30 PM, you wrote: Before you go any further take a look at: /cgicc-3.2.3/contrib/fcgi-test.cpp and FCgiIO.cpp FCgiIO.h in cgicc package. mggn> Hello @All. mggn> I hope anyone can help me on this topic. I'm trying to use the cgicc library in a FastCgi environment. mggn> Therefore I want to subclass CgiInput as described in the cgicc documentation. My FastCgiInput class looks as follows: -- www.rol.ru Best regards, Igor mailto:sprog@... _______________________________________________ help-cgicc mailing list help-cgicc@... http://lists.gnu.org/mailman/listinfo/help-cgicc |
| Free embeddable forum powered by Nabble | Forum Help |