Wierd error?

closed account (SECMoG1T)
Hi, why does this simple class require me to have a constructor or destructor, it doesn't make sense.


1
2
3
4
5
6
7
8
9
10
11
12
struct callable
{
   template<typename T,typename N>
   operator()(T t,N n);
};

template<typename T,typename N>
void callable::operator()(T t,N n)
{
    auto final_value=(t*n)/1.146;
    std::cout<<"final : "<<final_value;
}  



Error!

C:\Users\orion\Desktop\Custom\Synl\signal.cpp|9|error: expected constructor, destructor, or type conversion before ';' token|
1
2
3
4
5
struct callable
{
   template<typename T,typename N>
   operator()(T t,N n);
};
Only constructor, destructors and conversion operators do not state return values.

You need to declare operator() return type.
closed account (SECMoG1T)
Haha ,Thanks @Minnipaa , that was yet another stupid mistake ,how din't i spot that , av spent a lot of time debugging and rebuilding my project hehe , Thanks again.
> error: expected constructor, destructor, or type conversion before ';' token
>> how din't i spot that , av spent a lot of time debugging and rebuilding my project

If a procedure named INSIGHT has been defined and then called seventeen times in the program, and the eighteenth time it is misspelt as INSIHGT, woe to the programmer. The compiler will baulk and print a rigidly unsympathetic error message, saying that it has never heard of INSIHGT. Often, when such an error is detected by a compiler,the compiler tries to continue, but because of its lack of insihgt, it has not understood what the programmer meant. In fact, it may very well suppose that something entirely different was meant, and proceed under that erroneous assumption. Then a long series of error messages will pepper the rest of the program, because the compiler - not the programmer - got confused. Imagine the chaos that would result if a simultaneous English-Russian interpreter, upon hearing one phrase of French in the English, began trying to interpret all the remaining English as French. Compilers often get lost in such pathetic ways. C'est la vie.
Douglas Hofstadter in 'Godel, Escher, Bach: an Eternal Golden Braid'


Particularly when learning C++, consider running the code through more than one compiler.
Even if one of them get confused, another one may not. Even if one of them passes non-conforming code, another one may spit out an error.

1
2
3
4
5
struct callable
{
   template<typename T,typename N>
   operator()(T t,N n);
};


GNU (lack of insihgt):
main.cpp:4:23: error: expected constructor, destructor, or type conversion before ';' token
      operator()(T t,N n);
                         ^


LLVM (excellent: insightful and extra helpful):
main.cpp(4,5): error : C++ requires a type specifier for all declarations
      operator()( T t, N n );
      ^


Microsoft (good enough to tell us what the error is):
source_file.cpp(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
closed account (SECMoG1T)
Wow that's amazing @JLBorges great advice there, i swear av never tried that except on instances where one compiler fails to support a feature, well i definitely agree it is worth trying and i bet from today that will be the first option on my debugging cheat list, thank you very much.
Last edited on
Topic archived. No new replies allowed.