I have two .cpp files one is main1.cpp and second main2.cpp. I have function on main2.cpp which I am calling on main1.cpp via header file named main2.h.
I am getting error and it says "Undefined reference to Printlines"
This one is main1.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include "main2.h"
usingnamespace std;
int main()
{
char CharToDisplay;
int NumberOfChar, RowToDisplay;
// Prompt the user to enter a value
cout << "Enter any positive decimal integer value: ";
// To get char into ch
cin >> CharToDisplay >> NumberOfChar >> RowToDisplay;
Printlines (CharToDisplay, NumberOfChar, RowToDisplay);
return 0;
}
You probably haven’t given the proper compilaton instruction to your IDE. Your code compiles and runs in W10 + MinGW by the following intruction:
g++ -std=c++2a -Werror -Wall -Wextra -Wpedantic -Wshadow -O2 main1.cpp main2.cpp -o main.exe
Output:
Enter any positive decimal integer value: G 5 10
GGGGG
GGGGG
GGGGG
GGGGG
GGGGG
GGGGG
GGGGG
GGGGG
GGGGG
GGGGG