Seemingly basic C++ question
Alright, so this is annoying the hell out of me and I'm sure its a simple thing to do. Basically, I'm working with an open source C++ client called POCO to make a email client for a class...
Basically, I have a pop3 client object that retrieves emails from my email server, and then puts the emails in an object called MailMessage. Now, I want to be able to get my attachments, and the only functionality it seems that I have to do that is the following function:
static const std::string & contentTransferEncodingToString(
ContentTransferEncoding encoding
);
Problem is, I had no idea what the following was:
ContentTransferEncoding encoding
After digging into the source code, I found out it has something to do with "enums" (this is public by the way):
enum ContentTransferEncoding
{
ENCODING_7BIT,
ENCODING_8BIT,
ENCODING_QUOTED_PRINTABLE,
ENCODING_BASE64
};
Basically, the attachment I'm trying to open uses 7 bit encoding. Does ANYONE know how to deal with these enums, and how I can pass them into the contentTransferEncodingToString function?
Thank you so much for your efforts :)
EDIT:
So, unreal, but I didn't realize that the function I was trying to access was protected, it wasn't the enums, so the way you all suggested to access the enums was correct! And I guess the way I was trying to access them开发者_如何学Python was also correct =P. Just a big stupid mistake.
But thanks for all your efforts!!! Great community :)
You can either say
const std::string& s = contentTransferEncodingToString(ENCODING_7BIT)
or
const std::string& s = contentTransferEncodingToString(ContentTransferEncoding::ENCODING_7BIT)
I googled about your problem and I found this :
http://www.appinf.com/docs/poco/Poco.Net.MailMessage.html#16563
the complete namespace is Poco::Net::Message::ContentTransferEncoding so I would assume that you have to use either:
using namespace Poco::Net::Message;
or
string &s = contentTransferEncodingToString(Poco::Net::Message::ContentTransferEncoding::ENCODING_7BIT);
It's true that the function you are calling is protected and static, which meant you have must have something like this :
class test : public Poco::Net::MailMessage{
pubic:
std::string myFunc(){
// you can you the protected function here
return ContentTransferEncoding(ENCODING_7BIT);
// or
// because you have inherited all the class
// return CTE_7BIT;
}
Very simple, just call your function with an element of the enum:
std::string str = contentTransferEncodingToString(ENCODING_8BIT);
Enums are a enumeration. You could get the same result by defining a bunch of
const int ENCODING_7BIT = 0;
const int ENCODING_8BIT = 1;
However, what would happen if you pass a 8 to your function? Defining an enum allows to
- Restrict the number of items you allow
- Don't have to worry about how it is represented (thus having some abstraction)
Is the class that tries to call contentTransferEncodingToString inheriting from Poco::NET::MailMessage?
The method contentTransferEncodingToString is protected not public and can thus only be called from a class that inherits MailMessage.
If this isn't the problem could you please post the error message exactly as printed by the compiler.
Does ANYONE know how to deal with these enums, and how I can pass them into the contentTransferEncodingToString function?
Several answers have shown the basic way to use enum
s. When trying them you're getting error messages that the syntax is correct, but that the methods that use those enums
are not accessible from the scope you're in.
The answer, then, is to get into a scope where you can access what you want.
The methods in question are apparently protected
, which means the way to access them is through a derived class. I'm not saying this is good design, but it's clearly what POCO's designers expect you to use.
So, unreal, but I didn't realize that the function I was trying to access was protected, it wasn't the enums, so the way you all suggested to access the enums was correct! And I guess the way I was trying to access them was also correct =P. Just a big stupid mistake.
But thanks for all your efforts!!! Great community :)
精彩评论