Simple Class Errors

Started by
8 comments, last by rip-off 13 years, 11 months ago
Can someone please explain to me what I am doing wrong? I am trying to make a simple class:
class Quad {
protected:
	int X;
	int Y;
public:
	void SetValues(int x, int y) { X, Y = x, y; };
};
And when I make a new Quad:
Quad Billy;
Billy.SetValues(5,5);
But every time I try to compile, I get these errors:
1>c:\users\matt\documents\visual studio 2008\projects\ustest\ustest\objects.h(10) : error C2143: syntax error : missing ';' before '.'
1>c:\users\matt\documents\visual studio 2008\projects\ustest\ustest\objects.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\matt\documents\visual studio 2008\projects\ustest\ustest\objects.h(10) : error C2371: 'Billy' : redefinition; different basic types
1>        c:\users\matt\documents\visual studio 2008\projects\ustest\ustest\objects.h(9) : see declaration of 'Billy'
If I asked you for a hundred dollars would the answer to that question be the same as the answer to this question?
Advertisement
This is in Visual Studio 2008, BTW.
If I asked you for a hundred dollars would the answer to that question be the same as the answer to this question?
Post those two files in entirety: objects.h and whatever file has "Quad Billy" in it.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Objects.h:

class Quad {protected:	int X;	int Y;public:	void SetValues(int x, int y) { X, Y = x, y; };};


Objects.cpp:

#include "Objects.h"Quad Billy;Billy.SetValues(5,5);
If I asked you for a hundred dollars would the answer to that question be the same as the answer to this question?
X, Y = x, y; does not do what you think it does. Try X = x; Y = y; instead.

EDIT: I hadn't seen your latest post. Anyway, you can't just call a function like that. You'll have to do that inside another function.
Create-ivity - a game development blog Mouseover for more information.
This is it. I have other files, but none of them use these files because I just created them to test classes. I really have no clue how these errors are occurring.
If I asked you for a hundred dollars would the answer to that question be the same as the answer to this question?
Oh, that works. Why does it do that?
If I asked you for a hundred dollars would the answer to that question be the same as the answer to this question?
Quote:Original post by Matthew Shockley
Oh, that works. Why does it do that?
What works, and why does it do what?
Quote:Original post by Matthew Shockley
Oh, that works. Why does it do that?

That's just the proper way of saying what you're trying to say in C++. Assignment is a statement. Statements end in semicolons. To assign a sequence of values to a sequence of variables, you'll have to explicitly put them in lists. For example, you could do:

class Quad{protected:   vector<int> mValues;public:   void SetValues(const vector<int>& values) { mValues = values; }};

Not that I would recommend this in such a simple case.
You should google for the "comma operator". It doesn't do what you think it does.

This topic is closed to new replies.

Advertisement