#Why does it not work?

1 messages · Page 1 of 1 (latest)

atomic parrot
#
#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include <string>
#include <typeinfo>
#include <functional>
#include <concepts>
#include <cmath>
#include<ostream>
using namespace std;
template<typename T>
concept Number = integral<T> || floating_point<T>;

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);
template<typename T,typename E,typename K>
requires Number<T> && Number<E> && Number<K>
class graph{
    private:
    T(*GraphFunc)(E,K);
    public: 
    void plot();

};
template<typename T,typename E,typename K>
void graph::plot(){
    int z;
    for(int y=-15;y<=15;y++){
        if (y%5==0){cout<<setw(countDigit(15)+2)<<-y;}else{cout<<setw(countDigit(15)+4);}
        cout<< (y%5==0?"-|":"|");
        for(int x=-15;x<=15;x++){
            z = sign(GraphFunc(x,y))+sign(GraphFunc(x-1,y))+sign(GraphFunc(x,y-1))+sign(GraphFunc(x-1,y-1)); 
            if ((z<4) && (z>-4)){
                cout<<"--";
            } else if(y==0) {
                cout<<"- ";
            } else{
                cout<<"  ";
            }
        }   
}
int main(){}
foggy sphinxBOT
#

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.

errant pawnBOT
#
Compiler Output
<source>:35:6: error: 'template<class T, class E, class K>  requires (Number<T>) && (Number<E>) && (Number<K>) class graph' used without template arguments
   35 | void graph::plot(){
      |      ^~~~~
<source>: In function 'void plot()':
<source>:41:22: error: there are no arguments to 'GraphFunc' that depend on a template parameter, so a declaration of 'GraphFunc' must be available [-fpermissive]
   41 |             z = sign(GraphFunc(x,y))+sign(GraphFunc(x-1,y))+sign(GraphFunc(x,y-1))+sign(GraphFunc(x-1,y-1));
      |                      ^~~~~~~~~
<source>:41:22: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
<source>:41:43: error: there are no arguments to 'GraphFunc' that depend on a template parameter, so a declaration of 'GraphFunc' must be available [-fpermissive]
   41 |             z = sign(GraphFunc(x,y))+sign(GraphFunc(x-1,y))+sign(GraphFunc(x,y-1))+sign(GraphFunc(x-1,y-1));
      |                
atomic parrot
cold plover
#

Check the compilation output to find out your mistakes

atomic parrot
graceful vapor
#

without template arguments
35 | void graph::plot()

atomic parrot
#

;compile cpp -std=c++20```cpp
#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include <string>
#include <typeinfo>
#include <functional>
#include <concepts>
#include <cmath>
#include<ostream>
using namespace std;
template<typename T>
concept Number = integral<T> || floating_point<T>;

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);
template<typename T,typename E,typename K>
requires Number<T> && Number<E> && Number<K>
class graph{
private:
T(*GraphFunc)(E,K);
public:
void plot();

};

template<typename T,typename E,typename K>
void graph::plot(){
int z;
for(int y=-15;y<=15;y++){
if (y%5==0){cout<<setw(countDigit(15)+2)<<-y;}else{cout<<setw(countDigit(15)+4);}
cout<< (y%5==0?"-|":"|");
for(int x=-15;x<=15;x++){
z = sign(GraphFunc(x,y))+sign(GraphFunc(x-1,y))+sign(GraphFunc(x,y-1))+sign(GraphFunc(x-1,y-1));
if ((z<4) && (z>-4)){
cout<<"--";
} else if(y==0) {
cout<<"- ";
} else{
cout<<" ";
}
}
}
int main(){}

errant pawnBOT
#
Compiler Output
<source>:36:6: error: 'template<class T, class E, class K>  requires (Number<T>) && (Number<E>) && (Number<K>) class graph' used without template arguments
   36 | void graph::plot(){
      |      ^~~~~
<source>: In function 'void plot()':
<source>:42:22: error: there are no arguments to 'GraphFunc' that depend on a template parameter, so a declaration of 'GraphFunc' must be available [-fpermissive]
   42 |             z = sign(GraphFunc(x,y))+sign(GraphFunc(x-1,y))+sign(GraphFunc(x,y-1))+sign(GraphFunc(x-1,y-1));
      |                      ^~~~~~~~~
<source>:42:22: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
<source>:42:43: error: there are no arguments to 'GraphFunc' that depend on a template parameter, so a declaration of 'GraphFunc' must be available [-fpermissive]
   42 |             z = sign(GraphFunc(x,y))+sign(GraphFunc(x-1,y))+sign(GraphFunc(x,y-1))+sign(GraphFunc(x-1,y-1));
      |                
silver arch
#

I mean the first error is pretty clear

hollow spoke
#

how do you not know the basics...

#

and yet know how to use C++20 concepts

foggy sphinxBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.

foggy sphinxBOT
#

This question thread is being automatically marked as solved.

hollow spoke