看似基础的 C++问题

发布于 2024-08-12 05:34:07 字数 917 浏览 4 评论 0原文

好吧,这让我很烦,而且我确信这是一件简单的事情。基本上,我正在使用一个名为 POCO 的开源 C++ 客户端来为一个类制作一个电子邮件客户端...

基本上,我有一个 pop3 客户端对象,它从我的电子邮件服务器检索电子邮件,然后将电子邮件放入名为的对象中邮件消息。现在,我希望能够获取我的附件,而我必须执行的唯一功能似乎是以下功能:

static const std::string & contentTransferEncodingToString(
    ContentTransferEncoding encoding
);

问题是,我不知道以下是什么:

ContentTransferEncoding编码

在深入研究源代码后,我发现它与“枚举”有关(顺便说一下,这是公开的):

enum ContentTransferEncoding
    {
        ENCODING_7BIT,
        ENCODING_8BIT,
        ENCODING_QUOTED_PRINTABLE,
        ENCODING_BASE64
    };

基本上,我试图打开的附件使用 7 位编码。有谁知道如何处理这些枚举,以及如何将它们传递到 contentTransferEncodingToString 函数中?

非常感谢您的努力:)

编辑:

所以,不真实,但我没有意识到这一点 我试图访问的功能 受到保护,它不是枚举,所以 你们都建议的访问方式 枚举是正确的!我猜 我试图访问它们的方式是 也正确=P。简直就是个大傻子 错误。

但是感谢您的所有努力! 很棒的社区:)

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 was
also correct =P. Just a big stupid
mistake.

But thanks for all your efforts!!!
Great community :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

晨光如昨 2024-08-19 05:34:08

非常简单,只需使用枚举的元素调用函数即可:

std::string str = contentTransferEncodingToString(ENCODING_8BIT);

枚举是枚举。你可以通过定义一堆来得到相同的结果。

const int ENCODING_7BIT = 0;
const int ENCODING_8BIT = 1;

但是,如果你将 8 传递给你的函数会发生什么?定义枚举允许

  • 限制您允许的项目数量
  • 不必担心它的表示方式(因此具有一些抽象)

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)
酒中人 2024-08-19 05:34:08

尝试调用 contentTransferEncodingToString 的类是否继承自 Poco::NET::MailMessage?

方法 contentTransferEncodingToString 受到保护,不公开,因此可以只能从继承 MailMessage 的类中调用。

如果这不是问题,请您完全按照编译器打印的内容发布错误消息。

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.

没企图 2024-08-19 05:34:08

有谁知道如何处理这些枚举,以及如何将它们传递到 contentTransferEncodingToString 函数中?

几个答案已经展示了使用枚举的基本方法。尝试它们时,您会收到错误消息,提示语法正确,但无法从您所在的范围访问使用这些枚举的方法。

那么,答案就是进入您可以访问所需内容的范围。

这些方法显然是受保护的,这意味着访问它们的方式是通过派生类。我并不是说这是一个好的设计,但这显然是 POCO 的设计师希望你使用的。

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 enums. 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.

红玫瑰 2024-08-19 05:34:08

所以,不真实,但我没有意识到我试图访问的函数受到保护,它不是枚举,所以你们建议的访问枚举的方式是正确的!我想我尝试访问它们的方式也是正确的=P。只是一个大愚蠢的错误。

但感谢大家的努力!!!很棒的社区:)

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 :)

拍不死你 2024-08-19 05:34:07

你可以说

const std::string& s =  contentTransferEncodingToString(ENCODING_7BIT)

或者

const std::string& s =  contentTransferEncodingToString(ContentTransferEncoding::ENCODING_7BIT)

You can either say

const std::string& s =  contentTransferEncodingToString(ENCODING_7BIT)

or

const std::string& s =  contentTransferEncodingToString(ContentTransferEncoding::ENCODING_7BIT)
残龙傲雪 2024-08-19 05:34:07

我用谷歌搜索了你的问题,发现了这个:

http:// www.appinf.com/docs/poco/Poco.Net.MailMessage.html#16563

完整的命名空间是 Poco::Net::Message::ContentTransferEncoding 所以我假设你必须使用:


using namespace Poco::Net::Message;


string &s = contentTransferEncodingToString(Poco::Net::Message::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);
入怼 2024-08-19 05:34:07

确实,您正在调用的函数是受保护的和静态的,这意味着您必须有这样的东西:


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;

}

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;

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文