views:

100

answers:

3

I am pretty sure all of you are familiar with the concept of the Big4, and I have several stuffs to do print in each of the constructor, assignment, destructor, and copy constructor.

The restriction is this:

I CAN'T use more than one newline (e.g., ƒn or std::endl) in any method

I can have a method called print, so I am guessing print is where I will put that precious one and only '\n', my problem is that how can the method print which prints different things on each of the element I want to print in each of the Big4? Any idea? Maybe overloading the Big4?

+1  A: 

Maybe I don't understand the question completely because it is asked rather awkwardly, but can't you just have a function called newline that receives an ostream as an argument, and then simply prints '/n' to that output stream? Then you can just call that infinitely many times, while still abiding the arbitrary "one newline" rule.

e.g.

(edit: code removed, "smells like homework")

SauceMaster
A: 

I'm not sure I completely understand what you're trying to accomplish. Why is it that you can only use one newline? What makes it difficult to just write your code with only one newline in it? For example, I've done stuff like this before.

for(int i = 0; i < 10; i++) {
    cout << i << " ";
}
cout << std::endl;

If you need something more complicated, you might want to make some sort of print tracker object that keeps a flag for whether a newline has been printed, and adjusts its behavior accordingly. This seems like it might be a little overly complicated though.

Eric Holk
+1  A: 

print should take a parameter containing the information to output to the screen (sans '\n') and then call the c++ output method with in-line appending the '\n' to the passed in information.

note: no code 'cause this smells like homework to me...

beggs
I agree that this certainly smells like homework with such an arbitrary restriction on using code. I've removed the code snippet from my answer.
SauceMaster
well the method print itself doesn't take any argument, here's the method signature:print()and I can do something like a.print() as well which prints off something...
Alex
So the print() method is included in the assignment code? Can you share some of the code? Can you write additional functions (maybe overload the print() method?)
beggs