Reputation:
I wrote a c++ function what takes in an array and prints some stuff with no output, yet when I try and call it I get the error:
main.cpp:11:2: error: no matching function for call to 'render'
render(board);
^~~~~~
./functions.hpp:1:6: note: candidate function not viable: requires 0 arguments, but 1 was
provided
void render();
Here is my code:
I have a page for my functions (functions.hpp):
#include <iostream>
using namespace std;
void render(int board[]){
cout << board[0] << "\n";
}
Then my main file:
#include <iostream>
#include "functions.hpp"
using namespace std;
int main() {
string board[] = {"_", "_", "_", "_", "_", "_", " ", " ", " "};
render(board); // This is where I am hitting the error
}
Can someone point out the error, I am very new to c++.
Upvotes: 0
Views: 89
Reputation: 683
That should be in function.hpp:
#pragma once
#include <iostream>
using namespace std;
void render(string board[])
{
cout << board[0] << "\n";
}
and the .cpp file:
#include <iostream>
#include "function.hpp"
using namespace std;
int main() {
string board[] = { "_", "_", "_", "_", "_", "_", " ", " ", " " };
render(board); // This is where I am hitting the error
}
everything begins from wrong type of function argument but you still have int in you function in .hpp file
Upvotes: 1
Reputation: 70392
Your render
function accepts an array of integers, while you are trying to pass in an array of string
.
You can fix this by changing your function to accept the type you are trying to pass.
void render(string board[]){
cout << board[0] << "\n";
}
Your compiler output points to a function prototype for void render();
, which does not accept any arguments. You might be dealing with multiple header files with the same name (perhaps only varying by case). You will need to determine which header file is being included by your C++ source file, and then troubleshoot your code accordingly.
Upvotes: 2