It's a lie

Posts 1–5 of 5 · Page 1 of 1
It's a lie
I was reading a c++ book, and I usually type up something simmillar to the example for the lesson so it sticks, but when I did this I got 0 for my area. After close inspection I narrowed it down. Then retyped a simplified version to be sure, and now I'm sure I have no idea wtf is going lol. It's probably something obvious, but I don't see it. If you spot it that would be nice

*I know I'm using lots of inline functions, but I'm only using them once so it's fine.

header:
Code:
class wtf
{
public:
	wtf(int tempTop, int tempBottom, int tempLeft, int tempRight)
	{
		tempTop = top;
		tempBottom = bottom;
		tempLeft = left;
		tempRight = right;
	}
	~wtf() {};

	int getArea() const
	{
		int area, width, length;

		width = top - bottom;
		length = right - left;
		area = width*length;

		return area; }
private:
	int top, bottom, left, right;
};
main:
Code:
#include <iostream>
#include "rectangle.h"

int main()
{
	wtf test(10, 5, 5, 15);
	int area = test.getArea();

	std::cout << area << std::endl;
	
	return 0;
}
Quote Originally Posted by tdct View Post

header:
Code:
class wtf
{
public:
	wtf(int tempTop, int tempBottom, int tempLeft, int tempRight)
	{
		tempTop = top;
		tempBottom = bottom;
		tempLeft = left;
		tempRight = right;
	}
	~wtf() {};

	int getArea() const
	{
		int area, width, length;

		width = top - bottom;
		length = right - left;
		area = width*length;

		return area; }
private:
	int top, bottom, left, right;
};
better turn that around.

you are now giving the temporary variable the value of the real variable
Quote Originally Posted by Toxic Waltz View Post
better turn that around.

you are now giving the temporary variable the value of the real variable
Wow, rotfl, I know that's the way it goes, I just had blank moment. Thank you.
Quote Originally Posted by Toxic Waltz View Post
so everything works now?
Probably, I didn't check, but I know you are right about that being wrong. I could check, but I'd have to retype the entire cpp because I only made it to find the problem, so once you answered I deleted it.
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us