#Weird errors

1 messages · Page 1 of 1 (latest)

viral acorn
#

I am getting a lot of ostream errors when I compile with c++20

#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include <string>
#include <typeinfo>
#include <functional>
#include <concepts>
#include <cmath>
#include<ostream>
using namespace std;

int constexpr inline countDigit(long long n)
{
    if (n/10 == 0)
        return 1;
    return 1 + countDigit(n / 10);
}
int constexpr inline sign(int y){
    return clamp(y,-1,1);
}
//#define sign(n) clamp(n,-1,1);
#define axis  "+ ";
#define line  "# ";
#define graph "  ";
#define size 15
template<typename T>
concept Number = integral<T> || floating_point<T>;

template<typename T,typename E,typename K>
void k(T(*h)(E,K) ) requires Number<T> && Number<E> && Number<K>{
    int z;
    for(int y=-size;y<=size;y++){
        if (y%5==0){cout<<setw(countDigit(size)+2)<<-y;}else{cout<<setw(countDigit(size)+4);}
        cout<< (y%5==0?"-|":"|");
        for(int x=-size;x<=size;x++){
            z = sign(h(x,y))+sign(h(x-1,y))+sign(h(x,y-1))+sign(h(x-1,y-1)); 
            if ((z<4) && (z>-4)){
                cout<<line;
            } else if(y==0) {
                cout<<"- ";
            } else{
                cout<<graph;
            }
        }   
    cout<<'\n';

    }
}

int constexpr inline f(int x,int y){
    return x*x*x*x*x-350*x*x*x+9999*x-6500*y;
    //return (y*y/25)-(x*x/1.5*1.5)-1;
    //return y+x*x;
    //return y-5*x;
    //return y;
    //return y-tan(x);
    }

int main(){
    
    cout<<"\n";
    k(&f);
}```
btw I am using gcc version 12.2.0 mingw
split quailBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

viral acorn
split quailBOT
#

I am getting a lot of ostream errors when I compile with c++20


#include <algorithm>
#include <cmath>
#include <cmath>
#include <concepts>
#include <functional>
#include <iomanip>
#include <iostream>
#include <ostream>
#include <string>
#include <typeinfo>
using namespace std;

int constexpr inline countDigit(long long n) {
  if (n / 10 == 0)
    return 1;
  return 1 + countDigit(n / 10);
}
int constexpr inline sign(int y) {
  return clamp(y, -1, 1);
}
//#define sign(n) clamp(n,-1,1);
#define axis "+ ";
#define line "# ";
#define graph "  ";
#define size 15
template<typename T>
concept Number = integral<T> || floating_point<T>;

template<typename T, typename E, typename K>
void k(T (*h)(E, K)) requires Number<T>&& Number<E>&& Number<K> {
  int z;
  for (int y = -size; y <= size; y++) {
    if (y % 5 == 0) {
      cout << setw(countDigit(size) + 2) << -y;
    } else {
      cout << setw(countDigit(size) + 4);
    }
    cout << (y % 5 == 0 ? "-|" : "|");
    for (int x = -size; x <= size; x++) {
      z = sign(h(x, y)) + sign(h(x - 1, y)) + sign(h(x, y - 1)) +
          sign(h(x - 1, y - 1));
      if ((z < 4) && (z > -4)) {
        cout << line;
      } else if (y == 0) {
        cout << "- ";
      } else {
        cout << graph;
      }
    }
    cout << '\n';
  }
}

int constexpr inline f(int x, int y) {
  return x * x * x * x * x - 350 * x * x * x + 9999 * x - 6500 * y;
  // return (y*y/25)-(x*x/1.5*1.5)-1;
  // return y+x*x;
  // return y-5*x;
  // return y;
  // return y-tan(x);
}

int main() {
  cout << "\n";
  k(&f);
}

btw I am using gcc version 12.2.0 mingw

ThePlatypusEveryoneLoves
lunar matrix
#

also it seems to work fine on "my machine"

#
#

you're using gcc instead of g++ so maybe that's something

viral acorn
#

works fine online

granite escarp
#

the error is indeed that you use gcc instead of g++

#

for C++ code you need to use g++ as that invokes the linker et al. with different default options than gcc

#

also, these macros

#define axis "+ ";
#define line "# ";
#define graph "  ";
#define size 15

are kinda cursed

#

why not just make them constexpr variables?

alpine lava
alpine lava
viral acorn
alpine lava
#

and what happens when things like member functions are called .size :D

#

it just gets replaced

viral acorn
viral acorn
alpine lava
#

Hence why defines are bad

viral acorn
#

I thought you said vector.size was a define cppthonk

viral acorn
#

!solved