Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3936354
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:56:15+00:00 2026-05-19T23:56:15+00:00

I’m sure this question has already been asked in one form or another, but

  • 0

I’m sure this question has already been asked in one form or another, but I couldn’t find the clue. Please consider the following C++-code:

// A.h
class A
{
    public:
        A();
        virtual ~A();
        virtual void setVisibility(bool v);
        virtual bool setVisibility();

    protected:
        bool visibility;
};

// B.h
class B : public A
{
    public:
        B();
        virtual ~B();
};


// C.h
class C : public B
{
    public:
        C();
        virtual ~C();
        virtual void setVisibility(bool v);
        virtual bool setVisibility();
};

// A.cpp
#include "common.h"
A::A() {}
A::~A() {}
void A::setVisibility(bool v) { this->visibility = v; }
bool A::setVisibility() { return this->visibility; }

// B.cpp
#include "common.h"
B::B() {}
B::~B() {}

// C.cpp
#include "common.h"
C::C() {}
C::~C() {}
void C::setVisibility(bool v) { /* do nothing */ }
bool C::setVisibility() { return false; }

// common.h - does nothing else than joining the header files together
#include "A.h"
#include "B.h"
#include "C.h"

calling:

C* myC = new C();
cout << "Set visibility true" << endl;
myC->setVisibility(true);

I tried several things. If I declare both methods virtually in C, it compiles but I get a segmentation fault at myC->setVisibility(true). If I remove the declaration (which shouldn’t be necessary anyway, as they’re inherited from B and A, right?), then it tells me that C doesn’t have these methods.

And I don’t want to reimplement the methods in B. If I declare them everywhere including B, it tells me that there’s no implementation of these methods in B.

What should I do now? I need virtual, because I’m not always gonna use C as variable type in the calling example.

I’m using GCC on a 64 bit machine.


Edit: Corrected the copy/paste-mistake. I named the classes A, B and C for simplicity and didn’t copy the code correctly. But unfortunately, the problem remains


Edit 2: Added common.h


Edit 3: Hmm… copying this code actually works fluently. But the architecture is the same. Except that I compile my code into a shared library using the flags -shared -fPIC. The calling code is in the application that uses this library. Nothing else is different. Gotta check again.

Thanks for any tips pointing me to the right direction. regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:56:15+00:00Added an answer on May 19, 2026 at 11:56 pm

    The other answers are all correct before the correction. But it’s not the solution to the problem. There actually isn’t any problem at all. The problem lies in my implementation of the setVisibility-method, that’s where the segfault occurs. Therefore the solution can’t be found here.

    Thanks to all who tried to help!
    regards

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm making a simple page using Google Maps API 3. My first. One marker
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.