tetron 22 Junior Poster

const is a some what overrated concept that leads to more typing
and maintenance.

In your case myfunc is not const as it alters a member variable
if this is not appropriate to be altered then you need to use a local

double myfunc(double x1,double x2, double x3) const
{
std::vector<double> memory(4, 0.0);
//etc...
}

but your function does not necessarily want this either...
the const is telling the compiler that you are not altering the class
but that is what you are doing and there is no way that the compiler can resolve this problem.

There might be a way to cast the function to const but I don't know it...

the question is why does the other end need to know that your class variable is const....
it should not matter it is only that x1, x2, x3 are not changing that should matter where the function is called! so there is no logical need for the function to be declared const only the inputs!

tetron 22 Junior Poster

This is going to be a stupid question, but If I do use the

//tet: changed the function name and removed friend
bool greater_than (Rational &Fraction1, Rational &Fraction2);

Operators are really just functions that the compiler can read in a user friendly manner

so to use this function

if(true == greater_than(r1, r2))
{
std::cout << "rational number r1 is bigger than r2" << std::end;
}

you should convert back to a single rational number I think if you work out in the short Rational example I gave whatshould go into the operator function it would help you

an operator> returns a bool this can be used with if etc

but it has a special layout

bool b = (r1 > r2);
if(b)
{
}
WaltP commented: Tetron, use periods and commas. I'll start infratcin if you keep making unreadable comments. -2
tetron 22 Junior Poster

I missed that this was code that you were not intending to use but although in some ways it is clean code stay well away from it

it is using () to turn a struct into a class
rather than using a global or a static it does the silly n++ better would have been but still not my choice

/*fill a with the numbers 0-9*/
#include <iostream>
#include <vector>
int main()
{
int sz(10);
int a[sz];

//fill a using an int
//param three needs to be function pointer or ()
int i(0);
//i have not tested i++ as a function that is allowed
std::generate(a, a+10, i++); 
/*
going from first to last of a 
calling ++i;
*/

/* a for loop would be a minimal overhead and a better choice for now
*/

std::vector<int> vb;
vb.reserve(sz);
for(int j(0); j < sz; ++j)
{
vb.push_back(j);
}

//line 14 does the same as this
for(int k(0); k< sz ; ++k)
{
std::cout << vb[k] <<  " ";
}

//iterators would be faster



return 0;
}
tetron 22 Junior Poster

Hello Everybody,

int operator()() { return n++; }

yikes this is not a good idea to call a function without a name I don't think I have ever wanted to overwrite the operator() this is overloading a constructor in a class, change the name or use operator++ Generate although I haven't used it clearly calls g() several times. I guess it populates a using g()

Your code seems to use some very odd/scary choices what is it supposed to be doing?

if you are learning C++ use a class not a struct

if you need a unique number in a constructor there are better ways to do this.

if you are asking about g() your choice of line 14 seems to be unwise. Use code that has a clear intention or comment it. Although, it might seem the best solution now you will end up using different containers.

tetron 22 Junior Poster

Assuming that your code was showing multiple files
including the same file indirectly

by adding the preprocessor line to the top of all of your .h files

#pragma once

you can ensure that no single file includes the same file twice.