编程风格? [英] Style of programing ?

查看:147
本文介绍了编程风格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个类有私有和公共类,我经常使用它们.
私人:包括数据输入
公共:包括方法,功能.一个功能仅返回一个输出,但是我想要更多的输出.我决定将输出设为私有,但我觉得这不是逻辑,它们不是课堂上的基础材料.

任何人都可以向我解释这个问题.我总是觉得一类人就像我们生命中的一个身体一样,我想实现真正的逻辑.

One class have private and public, i always use them.
private: include data input
public: include medthod, function. One function just only returns one output, but i want to more outputs. I decide make output in private but i feel it is not logic, they are not basical material in class.

Anybody can explain to me about this problem. I always feel one class like one body in our life and i want to it realy logic.

class Graph
{
private:
  int **m_piMatrix;
  int m_iSize;
//int length // not logic
// vector <int> listVerse;  // not logic
public:
  vector <int> ShortPathDijkstra (void)
  {
// i want return many outputs, such as length path, list of verse, 
// i think it is not logic when i put them in private
// i think private just only include inputs
  };
};

推荐答案

您可以使另一个类容纳要返回的所有值.然后,在您的ShortPathDijkstra方法中,创建该类的新实例,并用length和listVerse中的值填充它.然后返回该实例.该类可能看起来像这样:
You could make another class to hold all the values you want to return. Then, in your ShortPathDijkstra method, create a new instance of that class and fill it with the values from length and listVerse. Then return that instance. That class might look something like this:
class DijkstraResult
{
public:
	int length;
	vector listVerse;
};


请注意,如果需要,可以将其设为结构而不是类.


Note that you can make it a struct instead of a class if you want.


这是一个完全不同的问题.请为此提出一个新问题,而不要弄乱这个问题.虽然,但在进行此操作之前,请先进行一些Google搜索.在您立即在此处提出问题之前,请尝试一下.我们确实喜欢回答问题,但是我们希望您先完成大部分工作.
That''s an entirely different question. Please create a new question for that, rather than cluttering up this one. Although, please do some google searches before you do that. And try some stuff out before you immediately ask questions here. We do like to answer questions, but we prefer you do most of the work first.


对不起,我不太喜欢.也许您应该发布一些代码?

我编写了私有方法,该方法始终返回结果,有时这很有意义.您不能通过返回类型更改方法.您需要使用ref/out参数或返回包含值的集合或类以返回多个值.

这些都是关于您要问的问题的猜测,如果我没有回答您,编辑您的问题,添加一些代码,我相信我们可以做得更好.
I''m sorry, I don''t really follow. Perhaps you should post some code ?

I write private methods that return things all the time, sometimes that makes sense. You can''t alter a method by return type. You need to use ref/out parameters or return a collection or a class that contains values to return more than one value.

Those are all guesses as to what you''re asking, if I''ve not answered you, edit your question, add some code, and I''m sure we can do better.


这篇关于编程风格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆