Jump to content
  • Advertisement
Sign in to follow this  
Miss

Property setter doesn't return

This topic is 607 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The following code:
	class Foo
	{
		private int _bar;
		int bar
		{
			get { return _bar; }
			set { _bar = value; }
		}
	}

	void Main()
	{
		Foo x, y;

		// You can't do this
		x.bar = y.bar = 10;

		// You have to do this instead:
		x.bar = 10;
		y.bar = 10;
	}
Complains that "No matching signatures to 'Foo::set_bar(void)'". Instead, you have to set them individually.

If I do this:
int get_bar() { return _bar; }
int set_var(int v) { _bar = v; return _bar; }
It says "The property has no set accessor".

Not sure if this is a bug or a missing feature though. Edited by Ansjh

Share this post


Link to post
Share on other sites
Advertisement

It would be a missing feature.

 

I'll look into what it would take to allow chaining assignments involving virtual properties. It would probably involve a different change than to have the set-accessor return a value though. Probably the compiler should be rewriting the statement to the following:

 

// this 
x.bar = y.bar = 10;
 
// becomes
auto temp = 10;
y.set_bar(temp);
x.set_bar(temp);

Share this post


Link to post
Share on other sites

Regarding the above solution, please bear in mind the following code:

class Object {
  float real;
  private float _virt;
  float get_virt() const {
    return _virt;
  }
  void set_virt(float val) {
    _virt = val;
  }
}
void main() {
  Object obj;
  any a;

  // Sets a to float 123.f
  a = obj.real = 123;

  // Would intuitively set a to float 123.f but in the proposed solution sets it to int 123 instead
  a = obj.virt = 123;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!