[solved] Allocating an object of abstract class type

Hey,

This may be a stupid question but can someone please explain why i am getting the error below? It presented itself after i added the sdkbox::FacebookListener.

SceneStart.h

Hi @undrex

The fact is you need to override all the virtual functions present inside FacebookListener
that would solve the issue.

Thanks for your quick answer. Would you mind give me an example how i would to this? I tried to google it.

I am pretty new to c++

Thanks!

Add these function declaration to StartScene.h

private:
    void onLogin(bool isLogin, const std::string& msg);
    void onPermission(bool isLogin, const std::string& msg);
    void onAPI(const std::string& tag, const std::string& jsonData);
    void onSharedSuccess(const std::string& message);
    void onSharedFailed(const std::string& message);
    void onSharedCancel();
    void onFetchFriends(bool ok, const std::string& msg);

and declare them with blank body in the StartScene.cpp file

like this -

/*********************
 * Facebook callbacks
 *********************/
void SplashScene::onLogin(bool isLogin, const std::string& error)
{
    CCLOG("##FB isLogin: %d, error: %s", isLogin, error.c_str());
    
    if (isLogin)
    {
        CCLOG("______________LOGGED IN______________");
    }
    
    std::string title = "login ";
    title.append((isLogin ? "success" : "failed"));
//    MessageBox(error.c_str(), title.c_str());
}

void SplashScene::onAPI(const std::string& tag, const std::string& jsonData)
{
    CCLOG("##FB onAPI: tag -> %s, json -> %s", tag.c_str(), jsonData.c_str());
}

void SplashScene::onSharedSuccess(const std::string& message)
{
    CCLOG("##FB onSharedSuccess:%s", message.c_str());
    
//    MessageBox(message.c_str(), "share success");
}

void SplashScene::onSharedFailed(const std::string& message)
{
    CCLOG("##FB onSharedFailed:%s", message.c_str());
    
//    MessageBox(message.c_str(), "share failed");
}

void SplashScene::onSharedCancel()
{
    CCLOG("##FB onSharedCancel");
    
//    MessageBox("", "share cancel");
}

void SplashScene::onPermission(bool isLogin, const std::string& error)
{
    CCLOG("##FB onPermission: %d, error: %s", isLogin, error.c_str());
    
    std::string title = "permission ";
    title.append((isLogin ? "success" : "failed"));
//    MessageBox(error.c_str(), title.c_str());
}

void SplashScene::onFetchFriends(bool ok, const std::string& msg)
{
    CCLOG("##FB %s: %d = %s", __FUNCTION__, ok, msg.data());
    
    const std::vector<sdkbox::FBGraphUser>& friends = PluginFacebook::getFriends();
    for (int i = 0; i < friends.size(); i++)
    {
        const sdkbox::FBGraphUser& user = friends.at(i);
        CCLOG("##FB> -------------------------------");
        CCLOG("##FB>> %s", user.uid.data());
        CCLOG("##FB>> %s", user.firstName.data());
        CCLOG("##FB>> %s", user.lastName.data());
        CCLOG("##FB>> %s", user.name.data());
        CCLOG("##FB>> %s", user.isInstalled ? "app is installed" : "app is not installed");
        CCLOG("##FB");
    }
    
//    MessageBox("", "fetch friends");
}

This will help you.

1 Like

Thanks for your time m8.

Already tried that and still same error :frowning:

could you do one thing please… ??

I have surely missed one of the virtual function.
Please check that FacebookListener class,
there should be some other virtual functions I have missed.

If you have any doubts regarding that, please post the code of the .h and .cpp file here, I will sort it out.

1 Like

Thanks alot man! I declared all the functions from FacebookListener and now it compiles fine.

But i dont really understand why. Could you please point me in the right direction where i can understand this :smile:

Thanks!

This is basic C++ concept.
If you are inhering an abstract class, you have to define all the virtual members, otherwise declare them as virtual in the inheriting class as well.

Just google it, you will find it.

1 Like

actually this is not true.
If you want to instantiate a derived class, you must override all methods which were declared pure virtual in the base class. If one of such method was declared virtual but not pure, then there is no need of overriding it.
Also, declaring virtual a method which was already declared virtual in a base class does nothing.

1 Like

Yes, that’s true.

Oh… yes, pure virtual. My bad :stuck_out_tongue_winking_eye: