ctor problems

Joined
Oct 16, 2007
Messages
4
Reaction score
0
I am getting an unusual error when attempting to construct a class. It could be that i just dont understand what the compiler is trying to tell me. but i Think that i should be able to call the ctor the way i am. I have created a small code snipped below that duplicates the problem. I am using gcc version 4.1.1 on red hat linux. any help would be appreciated

Code:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <sstream>

namespace Eds{
namespace Units{
typedef double BaseType;
class Meters
{
public:
    explicit Meters(BaseType i_value = 0.0) : m_store(i_value){};
    virtual ~Meters(){};
private:
	BaseType m_store;
};

}//end namespace units

namespace Common{

class DistanceType
{
public:
	DistanceType(){};
    DistanceType(Eds::Units::Meters x, Eds::Units::Meters y, Eds::Units::Meters z) :
     m_x(x),m_y(y),m_z(z){};
	virtual ~DistanceType(){};
    
	Eds::Units::Meters magnitude() const {return Eds::Units::Meters(0.0);};

private:
	Eds::Units::Meters m_x;
	Eds::Units::Meters m_y;
	Eds::Units::Meters m_z;
};
}//end namespace common
}//end namespace Eds


int main(void) {
	
	{
		
		Eds::Common::DistanceType offsets(
			Eds::Units::Meters(x), //x y and z are not declared yet but no error from compiler
			Eds::Units::Meters(y),
			Eds::Units::Meters(z));
		offsets.magnitude(); //error: request for member ‘magnitude’ in ‘offsets’, which is of non-class type ‘Eds::Common::DistanceType ()(Eds::Units::Meters, Eds::Units::Meters, Eds::Units::Meters)’
	}
	
	{

		double x = 10.0;
		double y = 15.0;
		double z = 20.0;
		
//this version does compiles correctly
		Eds::Common::DistanceType offsets = Eds::Common::DistanceType(
			Eds::Units::Meters(x),
			Eds::Units::Meters(y),
			Eds::Units::Meters(z));
		offsets.magnitude();
	}
	return EXIT_SUCCESS;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top