5 Replies - 259 Views - Last Post: 11 January 2013 - 09:04 AM Rate Topic: -----

#1 Arcand  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 08-January 13

Problem using user-defined data types

Posted 11 January 2013 - 08:24 AM

So im trying to make my own data type out of a class that takes two integers, in this case x and y, for the use of a non std container type. the type im using is simmilar to standard types, but it was made by a person I know that has been coding for a long time and it is simply more effecient, so I dont think its a problem with that I think im mis-understanding user-defined data types

as far as I know

room_dimensions::room_dimensions (int inX, int inY) // Constructor to call when x and y values are present
     {
        int x = inX;
        int y = inY;
     }



should accept use such as vector<room_dimensions> sample, or in my case, SGL_QUEUE<class room_dimensions> sample_grid; but either way its not taking it. Did I miss something in my learning of user defined classes as data types or...

Any help would be appreciated. Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Problem using user-defined data types

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,737
  • Joined: 08-August 08

Re: Problem using user-defined data types

Posted 11 January 2013 - 08:33 AM

Lines 3 and 4 are defining new local variables (x and y) and setting them. When the function is finished those variables are lost. You want to set the object's variables:
class example {
public:
	int x, y;
	
	void set_them(int newx, int newy) {
		x = newx;
		y = newy;
	}
	
};

Was This Post Helpful? 0
  • +
  • -

#3 Arcand  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 08-January 13

Re: Problem using user-defined data types

Posted 11 January 2013 - 08:50 AM

its still telling me int and room_divisions are incompatible?
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,737
  • Joined: 08-August 08

Re: Problem using user-defined data types

Posted 11 January 2013 - 08:55 AM

Code?
Was This Post Helpful? 0
  • +
  • -

#5 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: Problem using user-defined data types

Posted 11 January 2013 - 08:56 AM

Please post a small complete program that illustrates your problem.

Jim
Was This Post Helpful? 0
  • +
  • -

#6 Arcand  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 08-January 13

Re: Problem using user-defined data types

Posted 11 January 2013 - 09:04 AM

hi I figured it out. I cant push the room_dimensions class with out telling it so as it seems.
sample_grid.put_tail(new room_dimensions(increment_x, increment_y));



is accepted =+)

thanks for not shutting me down the moment I said im using a non-standard list system :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1