Click here to Skip to main content
15,886,080 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
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
  };
};
Posted
Updated 1-Dec-09 10:15am
v4

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:
C++
class DijkstraResult
{
public:
	int length;
	vector listVerse;
};

Note that you can make it a struct instead of a class if you want.
 
Share this answer
 
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.
 
Share this answer
 
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.
 
Share this answer
 
I want to ask more question.
I don't understand much about vector.h
But i don't like static array, i like dynamic array.
Anybody can tell me more about vector.h
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900