error regarding class

Hello, I'm receiving an error when I compile my code for "project06.triangle.cpp". How can i fix the problem without changing any code in the header file?

Here's the code for project06.triangle.cpp:
******************************************************

#include "/user/cse232/Projects/project06.triangle.h"
#include <cmath>
#include <iostream>
#include <ostream>
#include <iomanip>

Triangle::Triangle( double SA, double SB, double SC )
{
SideA = SA;
SideB = SB;
SideC = SC;
}
void Triangle::validate()
{
if (SideA > 0.0 && SideB > 0.0 && SideC > 0.0)
{
Valid = true;
}
else
{
Valid = false;
}
}
bool Triangle::is_valid()
{
validate();
return Triangle.valid;
}

*********************************************
and the code for project06.triangle.h:
*********************************************
#ifndef TRIANGLE_
#define TRIANGLE_

using namespace std;
#include <iostream>

class Triangle
{
private:
double SideA, SideB, SideC;
bool Valid;
void validate();
public:
Triangle( double = 0.0, double = 0.0, double = 0.0 );
bool is_valid() const;
}
*******************************************
and I'm receiving the following error:

project06.triangle.cpp:177: error: prototype for 'bool Triangle::is_valid()' does not match any in class 'Triangle'
/user/cse232/Projects/project06.triangle.h:44: error: candidate is: bool Triangle::is_valid() const




function in the header is bool Triangle::is_valid() const, but in cpp you write bool Triangle::is_valid(). those are different things. just add const.
Last edited on
When I added "const", the previous error didn't come up, but I received this one instead:

project06.triangle.cpp: In member function 'bool Triangle::is_valid() const':
project06.triangle.cpp:179: error: passing 'const Triangle' as 'this' argument of 'void Triangle::validate()' discards qualifiers
I think your professor wants you to call validate() from the constructor, not from is_valid(). is_valid() is
simply supposed to return Valid.
ah, that makes more sense. thank you.
Topic archived. No new replies allowed.