Jul 2, 2014 at 8:24pm UTC
I am trying to call a function though a variable
Please tell me what I am doing wrong
The error
|error: no match for 'operator=' (operand types are 'std::string {aka std::basic_string<char>}' and 'void')|
|warning: statement has no effect [-Wunused-value]|
||=== Build failed: 1 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <stdio.h>
#include <windows.h>
using namespace std;
class Createc{
public:
string function_call;
void Create()
{
function_call = thefuction();
function_call;
}
void thefuction()
{
cout << "plz help" << endl;
system("Pause");
}
};
int main()
{
Createc create;
create.Create();
}
Jul 2, 2014 at 8:31pm UTC
Your variable 'function_call' (terrible name by the way) is a string, your function "thefunction()" returns void (aka nothing) so there is nothing to assign to 'function_call'.
Jul 2, 2014 at 8:46pm UTC
I changed it to int and that worked!
Thank you
by the way the function_call is a terrible name but this was an example and I wanted it to be descriptive.
Jul 2, 2014 at 8:52pm UTC
It would compile if that's what you mean. I wouldn't say it "works" quite yet.
I only commented on the variable name because, to me, it makes it seem like it would be a Lambda or a std::function.