return-statement with a value, in function returning 'void' [-fpermissive]

Im trying to connect postgresql db from my server which has ubuntu 18.04
I have the code below but when i compile it I get the error

return-statement with a value, in function returning 'void' [-fpermissive]
return 1;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

#include <iostream>
#include <pqxx/pqxx> 

using namespace std;
using namespace pqxx;

void psqlconn() {
  
 connection C("dbname = db user = u1 password = mypwd* \
 hostaddr = 127.0.0.1 port = 5432");
 if (C.is_open()) {
     cout << "Opened database successfully: " << C.dbname() << endl;
      } 
 else {
       cout << "Can't open database" << endl;
         return 1;

      C.disconnect ();
   } 

}

int main() {
  psqlconn(); // call the function
  return 0; 
}


Last edited on
You declared and defined your function as void psqlconn(), the "void" signifying that it returned nothing.

Then you allowed it (in principle) to return 1;
thank you
Amazing tutorial! This is exactly the type of post we like to see on the tutorials board!




https://www.jcpenneykiosk.bid/
Topic archived. No new replies allowed.