Class with an array of another class syntax problem?

Started by
2 comments, last by theOcelot 14 years, 7 months ago
I have the two given classes:

	class Angle
	{
		public:
			Angle(int value,AngleType type);
		private:
			int value;
	};


And

	class Coordinate
	{
		public:
			Coordinate(int a,int b,Angle::AngleType type);
		private:
			Angle coords[2];
	};


My problem is that since i don't have a default constructor for Angle i have to initialize it to use it in Coordinate class. I thought i could do it like this:

Coordinate :: Coordinate(int a,int b,Angle::AngleType type) : coords{(a,type),(b,type)}


However that syntax isn't the right one :S I have searched Google but i was unable to find an answer since i cant really ask the question right. Does any one have any solution besides creating a default constructor? Thanks for reading this.
Advertisement
C++0x will have an initialization syntax like that. If you know that you'll only need two Angles, you don't gain much by having them in an array, so you may as well just use member variables, which can be init'ed in an init list. This would probably be my approach.

Looking at your second sample again, I think you would need to do the array like so:
Coordinate(int a,int b,Angle::AngleType type) : coords{Angle(a, type), Angle(b, type)}
with the Angle constructor, anyway. If you're using a recent GCC compiler, that may actually work.

For what it's worth, Coordinate's constructor will be small enough that it may as well be inline. And just out of curiosity, what is AngleType?
Hi there theOcelot thanks for your idea but i have tried that already and it doesn't work :S.
I have already tried that:
Quote:
Looking at your second sample again, I think you would need to do the array like so:

Coordinate(int a,int b,Angle::AngleType type) : coords{Angle(a, type), Angle(b, type)}

Basically i try to create a program that will read Garmin gps maps and it has a 3 byte and four byte variant.
The AngleType is used to convert both types to 4 byte for easier comparison.
For now i just made the array an array of pointers,however i want to find the syntax since i have had the problem before and from curiosity.

[Edited by - DigitalBeing on September 15, 2009 6:40:30 AM]
Tried which? I'm confused.

This topic is closed to new replies.

Advertisement