Linker issue ?

I'm doing the following problem :

Add on to your Rectangle class from last time:

1)Create a new class TestRect which is a friend class of Rectangle. Inside this class, implement a member function called TestRect::tester, which takes a rectangle as a parameter and tests that both length and width are > 0.

2)Create a main() function which makes three rectangles r1, r2, and r3, each of which has length and width 20. Then call your TestRect::tester function on each of these rectangles and print out the result

I think I did part 1) correctly but part 2) does not give me the output I'm looking for. I do not know how to fix my code from the following output I got :

rect.cpp:69:1: warning: non-void function does not return a value [-Wreturn-type]
}
^
1 warning generated.
Undefined symbols for architecture x86_64:
  "TestRect::tester(Rectangle&)", referenced from:
      _main in rectEnhanceStaticFriends.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
cppcompile:15: no such file or directory: ./rectEnhanceStaticFriends


can you help me how to fix it? Seems a linker issue, that I don't find??

Here is my code. (Be aware that there is of portion of code from a previous pb I did. In order to not confuse you guys, understand that this portion of code didn"t affect the current problem I'm doing. Actually it's coming from the "Add on to your Rectangle class from last time:"


My main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream> //
#include <iomanip>
#include <cstring>
#include <string>
#include "rect.h"
using namespace std;

int main()
{

    Rectangle::setYards(100);
    Rectangle r1(20, 20, "Kitchen");
    Rectangle r2(20, 20, "Bathroom");
    Rectangle r3(20, 20, "Office");
    TestRect tr;

    cout << "Test on r1: " << tr.tester(r1) << endl;
    cout << "Test on r2: " << tr.tester(r2) << endl;

    Rectangle house[] = {Rectangle(10, 12, "Kitchen"),
                         Rectangle(20, 20, "Bedroom"),
                         Rectangle(8, 12, "Offce")};

    for (int i = 0; i < 3; i++)
    {

        if (strcmp(house[i].printName(), "Offce") == 0)
        {
            // cout << "oui\n";
            house[i].setName("Office");
        };

        cout << "Area for " << house[i].printName() << " is : " << house[i].getArea() << endl;
    }

    if (house[1].getArea() > house[2].getArea() && house[1].getArea() > house[3].getArea())
    {
        cout << house[1].printName() << " has the biggest area.\n";
    }
    else if (house[2].getArea() > house[1].getArea() && house[2].getArea() > house[3].getArea())
    {
        cout << house[2].printName() << " has the biggest area\n";
    }
    else
    {
        cout << house[3].printName() << " has the biggest area\n";
    }

    return 0;
}


testRect.h
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef TESTRECT_H
#define TESTRECT_H

class Rectangle; //forward declaration of class Rectangle

class TestRect
{
public:
    bool tester(Rectangle &);
};

#endif 


testRect.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  #include <iostream> //
#include <iomanip>
#include <string>
#include "testRect.h"
#include "rect.h"

bool TestRect::tester(Rectangle &r)
{
    bool testResult = false;
    if (r.width > 0 && r.length > 0)
        testResult = true;
    return testResult;
}


rect.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  // Rec header file
#ifndef RECT_H
#define RECT_H
#include "testRect.h"

class Rectangle
{
private:
    double width;
    double length;
    char *name;
    static double yardsAvail; //indicate how many yards of perimeter are available to make rectangle
    void initName(const char *n);
    void initName(const char *n, int size);

public:
    //constructors
    Rectangle();
    Rectangle(double, double,
              const char *);
    //destructor
    ~Rectangle() { delete[] name; };
    void setWidth(double);
    void setLength(double);
    void setWidth(char *);
    void setLength(char *);
    void setName(const char *);
    int getWidth() const;
    int getLength() const;
    double getArea() const;
    char *printName() const
    {
        return name;
    }
    static double setYards(double);
    friend bool TestRect::tester(Rectangle &);
    friend class TestRect;
};

double Rectangle::yardsAvail = 0;

#endif 


rect.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  #include <iostream> //
#include <iomanip>
#include <string>
#include "rect.h"
#include "testRect.h"
using namespace std;

Rectangle::Rectangle()
{
    width = 0;
    length = 0;
    initName("Default");
}

Rectangle::Rectangle(double x, double y, const char *z)
{
    width = x;
    length = y;
    initName(z);

    double yardsReqd = 2 * x + 2 * y;
    if (yardsAvail - yardsReqd < 0)
    {
        cout << "Not enough yard..\n";
        width = 0;
        length = 0;
    }

    yardsAvail -= yardsReqd;
}

void Rectangle::initName(const char *n)
{
    name = new char[258];
    strcpy(name, n);
};

void Rectangle::initName(const char *n, int size)
{
    name = new char[size];
    strcpy(name, n);
};

void Rectangle::setWidth(double w)
{
    width = w;
}

void Rectangle::setLength(double l)

{
    length = l;
}

void Rectangle::setName(const char *newname)
{
    //newname.newName = "Office";
    strcpy(name, newname);
}

double Rectangle::getArea() const
{
    return width * length;
}

double Rectangle::setYards(double y)
{
    yardsAvail = y;
}
Hello siid14,

For now the warning is the easy part.

In "rec.cpp" the function "double Rectangle::setYards(double y)", at the bottom, promises to return a double, but the function does not return anything. Either make it a void function or return something.

Not sure about the other part yet, but it may go away when you fix the warning.

Andy
I cleared the warning with changing to a void function.

Now, I got this output with the warning fixed :


Undefined symbols for architecture x86_64:
  "TestRect::tester(Rectangle&)", referenced from:
      _main in rectEnhanceStaticFriends.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
cppcompile:15: no such file or directory: ./rectEnhanceStaticFriends
As one file, this compiles and runs OK (VS2019):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <iomanip>

class Rectangle
{
private:
	double width {};
	double length {};
	char* name {};
	static double yardsAvail;	//indicate how many yards of perimeter are available to make rectangle
	void initName(const char* n, int size = 258);

public:
	//constructors
	Rectangle();
	Rectangle(double, double, const char*);
	//destructor
	~Rectangle() { delete[] name; };
	void setWidth(double);
	void setLength(double);
	void setName(const char*);
	double getWidth() const { return width; }
	double getLength() const {return length; }
	double getArea() const;
	char* getName() const { return name; }
	static void setYards(double);
	friend class TestRect;
};

double Rectangle::yardsAvail {};

class TestRect {
public:
	bool tester(const Rectangle&);
};

Rectangle::Rectangle() {initName("Default"); }

Rectangle::Rectangle(double x, double y, const char* z) : width(x), length(y) {
	initName(z);

	const double yardsReqd {2 * x + 2 * y};

	if (yardsAvail < yardsReqd) {
		std::cout << "Not enough yard..\n";
		width = 0;
		length = 0;
	}

	yardsAvail -= yardsReqd;
}

void Rectangle::initName(const char* n, int size)
{
	// WARNING RE POSSIBLE BUFFER OVERFLOW
	name = strcpy(new char[size], n);
};

void Rectangle::setWidth(double w)
{
	width = w;
}

void Rectangle::setLength(double l)
{
	length = l;
}

void Rectangle::setName(const char* newname)
{
	// POTENTIAL PROBLEM AS SIZE OF NEWNAME COULD BE GREATER THAN ALLOCATED SPACE
	strcpy(name, newname);
}

double Rectangle::getArea() const
{
	return width * length;
}

void Rectangle::setYards(double y)
{
	yardsAvail = y;
}

bool TestRect::tester(const Rectangle& r)
{
	return r.width > 0 && r.length > 0;
}

int main()
{
	Rectangle::setYards(2000);

	Rectangle r1(20, 20, "Kitchen");
	Rectangle r2(20, 20, "Bathroom");
	Rectangle r3(20, 20, "Office");

	TestRect tr;

	std::cout << "Test on r1: " << std::boolalpha << tr.tester(r1) << '\n';
	std::cout << "Test on r2: " << std::boolalpha << tr.tester(r2) << '\n';
	std::cout << "Test on r3: " << std::boolalpha << tr.tester(r3) << '\n';
}

Last edited on
Hello siid14,

When I fixed the function I did not get the warning, but the error message I did get form MSVS2017 is:

Error	LNK2005	"private: static double Rectangle::yardsAvail" (?yardsAvail@Rectangle@@0NA) already defined in Main V1.obj	

I believe that this is saying the same as what you are getting, but I have not figured out how to fix it yet.

I see that the solution is to put everything in 1 file and all your problems will go away.

I also wanted why you are using a character array and not a "std::string"?

I see that you are using "new" to create blocks of memory, but I did not see a "delete" to free this memory before the program ends. The "std::string" puts its memory on the heap, but it cleans its-self up before the program ends.

I do not know if making the private variable "yardsAvail" static is the start of the problem or if it is the double Rectangle::yardsAvail = 0; that the compiler is thinking is being defined twice.

A thought I have is that "yardsAvail" should be given a value in the overloaded ctor. This may require a 4th parameter.

Andy
but I did not see a "delete" to free this memory before the program ends.


It's there in the rect.h file L22 and in my code L 18

A thought I have is that "yardsAvail" should be given a value in the overloaded ctor. This may require a 4th parameter.


I wouldn't as it's static. There's already a class static function setYards().

Error LNK2005 "private: static double Rectangle::yardsAvail" (?yardsAvail@Rectangle@@0NA) already defined in Main V1.obj


The issue here is that yardsAvail is defined in rect.h (L40) - which is included in multiple compilation units. The easiest fix is to move this to just before int main() - or to make it inline.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <iomanip>

class Rectangle
{
private:
	double width {};
	double length {};
	char* name {};
	inline static double yardsAvail {};	//indicate how many yards of perimeter are available to make rectangle
	void initName(const char* n, int size = 258);

public:
	//constructors
	Rectangle();
	Rectangle(double, double, const char*);
	//destructor
	~Rectangle() { delete[] name; };
	void setWidth(double);
	void setLength(double);
	void setName(const char*);
	double getWidth() const { return width; }
	double getLength() const { return length; }
	double getArea() const;
	char* getName() const { return name; }
	static void setYards(double);
	friend class TestRect;
};

class TestRect {
public:
	bool tester(const Rectangle&);
};

Rectangle::Rectangle() { initName("Default"); }

Rectangle::Rectangle(double x, double y, const char* z) : width(x), length(y) {
	initName(z);

	const double yardsReqd {2 * x + 2 * y};

	if (yardsAvail < yardsReqd) {
		std::cout << "Not enough yard..\n";
		width = 0;
		length = 0;
	}

	yardsAvail -= yardsReqd;
}

void Rectangle::initName(const char* n, int size)
{
	// WARNING RE POSSIBLE BUFFER OVERFLOW
	name = strcpy(new char[size], n);
};

void Rectangle::setWidth(double w)
{
	width = w;
}

void Rectangle::setLength(double l)
{
	length = l;
}

void Rectangle::setName(const char* newname)
{
	// POTENTIAL PROBLEM AS SIZE OF NEWNAME COULD BE GREATER THAN ALLOCATED SPACE
	strcpy(name, newname);
}

double Rectangle::getArea() const
{
	return width * length;
}

void Rectangle::setYards(double y)
{
	yardsAvail = y;
}

bool TestRect::tester(const Rectangle& r)
{
	return r.width > 0 && r.length > 0;
}

int main()
{
	Rectangle::setYards(2000);

	Rectangle r1(20, 20, "Kitchen");
	Rectangle r2(20, 20, "Bathroom");
	Rectangle r3(20, 20, "Office");

	TestRect tr;

	std::cout << "Test on r1: " << std::boolalpha << tr.tester(r1) << '\n';
	std::cout << "Test on r2: " << std::boolalpha << tr.tester(r2) << '\n';
	std::cout << "Test on r3: " << std::boolalpha << tr.tester(r3) << '\n';
}

Last edited on
Hello siid14,

In "main" you have:
1
2
3
4
    Rectangle::setYards(100);
    Rectangle r1(20, 20, "Kitchen");
    Rectangle r2(20, 20, "Bathroom");
    Rectangle r3(20, 20, "Office");

in line 1 "Rectangle is the class not an object of the class. You need an object of the class, (r1, r2 and r3), before you can call the function.

When I did this:
1
2
3
4
Rectangle r1(20, 20, "Kitchen");
Rectangle r2(20, 20, "Bathroom");
Rectangle r3(20, 20, "Office");
r1.setYards(100);

I also removed the "static" from the class.

This compiled with no errors or warnings. But has another problem. The overloaded ctor needs this value when it creates an object, but the value of "yardsAvail" is set after the fact.

It would work better, but untested, to set the value of "yardsAvail" in the overloaded ctor just before you have to use it. Then you will not need the last line in the above code.

Andy
@Andy. That defeats the purpose of avail. There is only a set amount of what is available across all usages. Hence a static is needed so that each instance can use this value. Otherwise you're setting an amount for each instance which is not what is intended. Part of this exercise is to learn how to use static in a class.

Last edited on
@seeplus,

You are right. I missed the delete in the dtor.

I have always had a problem with using static in a class. I do not see it that often to understand it better. Thank you for the tips.

Andy
If you really want this as 5 files as C++17:

rect.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#pragma once

class Rectangle
{
private:
	double width {};
	double length {};
	char* name {};
	inline static double yardsAvail {};	//indicate how many yards of perimeter are available to make rectangle
	void initName(const char* n, int size = 258);

public:
	//constructors
	Rectangle();
	Rectangle(double, double, const char*);
	//destructor
	~Rectangle() { delete[] name; };
	void setWidth(double);
	void setLength(double);
	void setName(const char*);
	double getWidth() const { return width; }
	double getLength() const { return length; }
	double getArea() const;
	char* getName() const { return name; }
	static void setYards(double);
	friend class TestRect;
};


testrect.h
1
2
3
4
5
6
#pragma once

class TestRect {
public:
	bool tester(const Rectangle&);
};


rect.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstring>
#include "rect.h"

Rectangle::Rectangle() { initName("Default"); }

Rectangle::Rectangle(double x, double y, const char* z) : width(x), length(y) {
	initName(z);

	const double yardsReqd {2 * x + 2 * y};

	if (yardsAvail < yardsReqd) {
		std::cout << "Not enough yard..\n";
		width = 0;
		length = 0;
	}

	yardsAvail -= yardsReqd;
}

void Rectangle::initName(const char* n, int size)
{
	// WARNING RE POSSIBLE BUFFER OVERFLOW
	name = strcpy(new char[size], n);
};

void Rectangle::setWidth(double w)
{
	width = w;
}

void Rectangle::setLength(double l)
{
	length = l;
}

void Rectangle::setName(const char* newname)
{
	// POTENTIAL PROBLEM AS SIZE OF NEWNAME COULD BE GREATER THAN ALLOCATED SPACE
	strcpy(name, newname);
}

double Rectangle::getArea() const
{
	return width * length;
}

void Rectangle::setYards(double y)
{
	yardsAvail = y;
}


testrec.cpp
1
2
3
4
5
6
7
#include "rect.h"
#include "testrec.h"

bool TestRect::tester(const Rectangle& r)
{
	return r.width > 0 && r.length > 0;
}


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <iomanip>
#include "rect.h"
#include "testrec.h"

int main()
{
	Rectangle::setYards(2000);

	Rectangle r1(20, 20, "Kitchen");
	Rectangle r2(20, 20, "Bathroom");
	Rectangle r3(20, 20, "Office");

	TestRect tr;

	std::cout << "Test on r1: " << std::boolalpha << tr.tester(r1) << '\n';
	std::cout << "Test on r2: " << std::boolalpha << tr.tester(r2) << '\n';
	std::cout << "Test on r3: " << std::boolalpha << tr.tester(r3) << '\n';
}

Hello siid14,

I have see this before, but do not recall whom it was for.

In your if statements:
1
2
3
4
5
6
7
8
9
10
11
12
if (house[1].getArea() > house[2].getArea() && house[1].getArea() > house[3].getArea())
{
    cout << house[1].printName() << " has the biggest area.\n";
}
else if (house[2].getArea() > house[1].getArea() && house[2].getArea() > house[3].getArea())
{
    cout << house[2].printName() << " has the biggest area\n";
}
else
{
    cout << house[3].printName() << " has the biggest area\n";
}

'house[1] is the 2nd element of the array, "house[2] is the 3rd element of the array and "house [3] is beyond the end of your array.

Looking at your set up:
1
2
3
4
5
6
Rectangle house[]
{
    Rectangle(10, 12, "Kitchen"),
    Rectangle(20, 20, "Bedroom"),
    Rectangle(8, 12, "Offce")
};

You could add a "dummy" rectangle at the beginning then start your following for loop at 1 instead of (0)zero.Or change your if statements so that "house" 1 is "house[0]" and so on.

BTW when I commented "double Rectangle::yardsAvail = 0;" from the "rec.h" file and put "double Rectangle::yardsAvail = 400;" just before "main" it worked.

I guess I war preoccupied with other parts to see the problem. Sorry about that.

Just as a test I changed:
1
2
3
4
5
6
7
Rectangle house[]
{
    Rectangle(0, 0, "Dummy"),  // <--- Added.
    Rectangle(10, 12, "Kitchen"),
    Rectangle(20, 20, "Bedroom"),
    Rectangle(8, 12, "Offce")
};


And the for loop to:
 
for (int i = 1; i < 4; i++)

The 1 place I do not like using (<=) is in a for loop. It is to easy to start the for loop at (0)zero and do 1 more loop than you need. If you are using the for loop to access an array you would be past the end of the array and that is a problem.

Andy
As the question was about TestRect, I never even looked at that code - and just deleted it! :)
Last edited on
I have see this before, but do not recall whom it was for.


For the same OP! See http://www.cplusplus.com/forum/beginner/278409/

Thank you for the catch for the house[3]. I haven't seen that since the program gave me what I was looking for. I'm looking through your comments and help right now to get my issue solved.. will keep you guys updated, thanks
@siid14 - the issue with house[3] was pointed out to you in your previous thread at http://www.cplusplus.com/forum/beginner/278409/ See my post 3rd from end.

If you haven't figured out the original problem yet, it's probably that you haven't included testRect.cpp in your project.
Hello siid14,

This is what I came up with using your code with a fwe changes:
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream> //
#include <iomanip>
#include <string>
#include <cstring>

#include "rect.h"

using namespace std;  // <--- Best not to use.

double Rectangle::yardsAvail = 400;

int main()
{
    Rectangle r1(20, 20, "Kitchen");
    Rectangle r2(20, 20, "Bathroom");
    Rectangle r3(20, 20, "Office");
    TestRect tr;

    cout <<
        std::boolalpha <<  // <--- Only needs done once.
        "Test on r1: " <<  tr.tester(r1) << "\n"
        "Test on r2: " <<  tr.tester(r2) << "\n"
        "Test on r3: " <<  tr.tester(r3) << "\n";  // <--- Added.

    Rectangle house[]
    {
        Rectangle(0, 0, "Dummy"),  // <--- Quick and dirty fix. The if statements need changed. Not adding this line.
        Rectangle(10, 12, "Kitchen"),
        Rectangle(20, 20, "Bedroom"),
        Rectangle(8, 12, "Offce")
    };

    std::cout << '\n';

    constexpr size_t ARR_SIZE{ sizeof(house) / sizeof(house[0]) };

    for (int i = 1; i < ARR_SIZE; i++)
    {
        if (strcmp(house[i].printName(), "Offce") == 0)
        {
            // cout << "oui\n";
            house[i].setName("Office");
        };

        cout << " Area for " << house[i].printName() << " is : " << house[i].getArea() << '\n';
    }

    // <--- These sub-scripts need changed.
    if (house[1].getArea() > house[2].getArea() && house[1].getArea() > house[3].getArea())
    {
        cout << "\n " << house[1].printName() << " has the biggest area.\n";
    }
    else if (house[2].getArea() > house[1].getArea() && house[2].getArea() > house[3].getArea())
    {
        cout << "\n " << house[2].printName() << " has the biggest area at " << house[2].getArea() << " square feet.\n";
    }
    else
    {
        cout << "\n " << house[3].printName() << " has the biggest area\n";
    }

    // <--- Keeps console window open when running in debug mode on Visual Studio. Or a good way to pause the program.
    // The next line may not be needed. If you have to press enter to see the prompt it is not needed.
    //std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
    std::cout << "\n\n Press Enter to continue: ";
    std::cin.get();

    return 0;  // <--- Not required, but makes a good break point.

}

In the program as a whole you would be better off using a "std::string" over the character pointer. Much easier to work with an no need for functions like "strcmp()" which could be a problem. I usually get that "strcmp()" and "strcpy()" is un-secure and should use "strcmp_s()" and "strcpy_s". This is an easy work around, but can be avoided using "std::string"s.

When I tried putting line 10 inside "main" even without the "double" at the beginning it did not work, but did work as a global variable.

I added line 23 because it just felt right. It is up to you if you want to keep it.

Line 35 was added to work with line 37. This is better than using a magic number in the for condition. Think about a file that has 1500 lines of code and 20 for loops all with magic numbers that need to change from 4 to 5. You will be very likely to miss 1 or 2 and that may not show up for awhile and it may be hard to find where you missed a change. The constant variable takes care of this problem. Normally you would just define the constant variable and only have 1 place to change it. The way this is done here all you have to do is make additions or deletions to the array to get the correct number.

Starting at line 49 the if statements need changed. Remember that arrays start at (0)zero not 1.


And I made a change to:
testRect.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//#include <iostream>  // <--- Not using any of these header files in this file.
//#include <iomanip>
//#include <string>

//#include "testRect.h"  // <--- Included through "rect.h".
#include "rect.h"

bool TestRect::tester(Rectangle &r)
{
    return (r.width > 0 && r.length > 0);  // <--- The () appear to be optional. Works either way in MSVS 2017.

    //bool testResult = false;

    //if (r.width > 0 && r.length > 0)
    //    testResult = true;

    //return testResult;
}

The header guard would keep line 5 from being compiled more than once, the same applies to lines 1 - 3, but it is not necessary to include what you do not need.

The single return statement will return return either (0)zero "false" or (1) true. No need for all the extra work.

Andy
Topic archived. No new replies allowed.