curl_easy_init() Segmentation fault

I have a class Libcurl which has a function Connect defined as :

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

bool Libcurl::Connect(const std::string& host, const std::string& username, const std::string& password, int port )
{
         m_Curl = curl_easy_init();
         if(!m_Curl)
        {
                return false;
        }
         m_Host = host;
         curl_easy_setopt(m_Curl, CURLOPT_URL, host.c_str());
         if(username.length())
         {
                curl_easy_setopt(m_Curl, CURLOPT_USERNAME, username.c_str());
         }
         if(password.length())
         {
                curl_easy_setopt(m_Curl, CURLOPT_PASSWORD, password.c_str());
         }
         if (INTERNET_DEFAULT_FTP_PORT != port)
         {
                curl_easy_setopt(m_Curl, CURLOPT_PROXYPORT , port);
         }
         return true;
}


and I have a main function
1
2
3
4
5
6
7
8
9
10
11
12
#include "FTPLibcurl.h"
#include <iostream>
using namespace std;

int main()
{
        Libcurl *file;
        if(file->Connect(<host>,<username>,<password>,21))
                cout<<"Connected"<<endl;

}



On compiling this with g++ -g -o curl Libcurl.cpp Main.cpp -I. -lcurl it compiles and gives an executable curl.

But on doing ./curl,it gives Segmentation fault(core dumped).


Can anyone please help me with this?


Libcurl *file;
This creates a pointer. It is currently pointing at some random memory somewhere.

if(file->Connect(...
This attempts to use that random memory somewhere as if it were a proper Libcurl object, which it is not. It is some random memory somewhere with random junk in it.

To use a Libcurl object, you have to actually make one first. Then, you make the pointer point at it.
Great...thanks Moschops....

How could I miss that..:)
Topic archived. No new replies allowed.