View Single Post
Old 10-28-2005, 07:57 PM   #12 (permalink)
Deliverance
C++ Beginner
 
Join Date: Jul 2005
Location: Ottawa
Posts: 73
Deliverance is on a distinguished road
Quote:
Originally Posted by Valmont
Hmm, before you go any further, can you explain me what's wrong with my code DESIGN-WISE?
Code:
#include <iostream>

using namespace std;

 
int add_it(const int a, const int b)
{ 
	std::cout << "Start Calculating."<<endl;
	return a+b;
}

void show_array(int* array, std::size_t size)
{
	for(std::size_t i = 0; i < size; ++i)
	{
		std::cout<<array[i]<<std::endl;
	}
}

int main()
{
 
  return 0;
}
1) firstly, you specified using namespace std, and provided to do std::cout and std::size_t everywhere.
2) in the for function, you are comparing size_t (which i think is a unsigned short initialized at 0 against a variable size which is also not initialized)
3) I don't believe the functions are related, or you are not showing any signs by leaving out both function calls in main. Those functions may as well not be there.
4) with a 1 liner for loop, I think it is preferrable to not use {} to encapsulate just the one line of code.

That's all I can gather from it...Am I on the right track?
Deliverance is offline   Reply With Quote