#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(){}
#Why does it not work?
1 messages · Page 1 of 1 (latest)
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.
;compile -std=c++20
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));
|
Raynei486#3955 | c++ | x86-64 gcc 12.2 | godbolt.org
yah and what does it mean
Check the compilation output to find out your mistakes
no idea what it means
without template arguments
35 | void graph::plot()
;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(){}
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));
|
ThePlatypusEveryoneLoves#0865 | c++ | x86-64 gcc 12.2 | godbolt.org
stil mo
I mean the first error is pretty clear
member function declarations need to know the templates used
template<typename T,typename E,typename K>
void graph<T,E,K>::plot(){
how do you not know the basics...
and yet know how to use C++20 concepts
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.
This question thread is being automatically marked as solved.
bozo me
I expected you to see and explain this, but you did not, how?