简体   繁体   中英

calling a function using defined header in C++

I am relatively new to C++. I am trying to call a function using defined header. I have following 2 files(in addition to enter.h file):

// 1. main.cpp

 #include "enter.h"
 #include<iostream>
 using namespace std;

 int main()
 {
 int intdemo=enter();
 cout << "The result is: " << intdemo<< endl;
}

// 2. enter.cpp

#include <iostream>
   using namespace std;
   int enter()
   {
   int thisisanumber;
     cout<<"Please enter a number: ";
     cin>>thisisanumber;
     return thisisanumber;
   }

I am getting the following error message "void value not ignored as it ought to be". and is pointed to the second line of the main function where value of the variable "intdemo" is assigned

Can anyone suggest how to fix this error? i have searched some of the similar posts here but cannot able to understand the problem. Since i am a beginner, any help would be appreciated.

Your header file probably declares the function enter() to return void (this was confirmed in the comments).

Changing this to match your function definition will solve the problem, as well as an unresolved external error you will most likely be getting as a side effect of this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM