3 Replies - 410 Views - Last Post: 02 November 2009 - 12:12 PM Rate Topic: -----

#1 javafun   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-October 09

what am i making mistake?

Posted 02 November 2009 - 11:04 AM


#include <iostream>
using namespace std;


class directions{
	int vertical;
	int horizontal;
public:

	directions (int n, int m){ vertical = n; horizontal = m;}


};


int main() {

	directions yon[8] = { {-1,0}, {-1,1}, {0,1}, {1,1}, {1,0}, {1,-1}, {0,-1},{-1,-1} }; // i have a mistake in this line

	return 0;
}
 


What is the mistake of mine? thank you..
Is This A Good Question/Topic? 0
  • +

Replies To: what am i making mistake?

#2 taylorc8   User is offline

  • B&

Reputation: 150
  • View blog
  • Posts: 1,572
  • Joined: 21-July 09

Re: what am i making mistake?

Posted 02 November 2009 - 11:17 AM

http://fredosaurus.c...ialization.html

This post has been edited by taylorc8: 02 November 2009 - 01:15 PM

Was This Post Helpful? 0
  • +
  • -

#3 mcrmcrmcr   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 30-October 09

Re: what am i making mistake?

Posted 02 November 2009 - 11:25 AM

One part is like class typed,one part is array with integers. Be careful to the equility of data types!!!!!
Was This Post Helpful? 0
  • +
  • -

#4 #define   User is offline

  • Duke of Err
  • member icon

Reputation: 1853
  • View blog
  • Posts: 6,671
  • Joined: 19-February 09

Re: what am i making mistake?

Posted 02 November 2009 - 12:12 PM

Interesting. Since the Class has a constructor you need to use that.

Here is your code with a little bit extra thrown in.
#include <iostream>
#include<iomanip>

using namespace std;


class directions{
	int vertical;
	int horizontal;
  public:

	directions (int n, int m){ vertical = n; horizontal = m;}
	void test() {cout << "(" << setw(2) << vertical << "," << setw(2) << horizontal << ")" << endl;}

};


int main() {

	directions yon[8] = { directions(-1, 0), directions(-1, 1),
						  directions( 0, 1), directions( 1, 1),
						  directions( 1, 0), directions( 1,-1),
						  directions( 0,-1), directions(-1,-1) };

	for(int t=0; t<8; t++) {yon[t].test();}

	cin.get();
	return 0;
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1