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

  • Home
  • SEARCH
  • 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 6126267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:21:05+00:00 2026-05-23T16:21:05+00:00

EDIT: I basically revamped the whole question so I could provide an executable example…

  • 0

EDIT: I basically revamped the whole question so I could provide an executable example…

I have been getting a segmentation fault that I can’t figure out. Here is a compacted version of my code. I maintained the original class hierarchy even though some of the classes have no relevant methods since I think that it has something to do with my issue, especially after some of the comments I’ve been getting.

#import <vector>
using namespace std;

template<class Data = float>
  class Vector
  {
    // All pure virtual functions.
  };

template<class Data>
  class TranslationVector : public virtual Vector<Data>
  {
    // All pure virtual functions.
  };

template<class Data>
  class SimpleVector4 : public virtual Vector<Data>
  {
    public:
      SimpleVector4(const Data d0, const Data d1, const Data d2, const Data d3)
      {
        fData = new vector<Data> ;

        fData->push_back(d0);
        fData->push_back(d1);
        fData->push_back(d2);
        fData->push_back(d3);
      }

      vector<Data>*
      getData()
      {
        return (fData);
      }

    private:
      vector<Data>* fData;
  };

template<class Data>
  class SimpleTranslationVector4 : public SimpleVector4<Data> , public TranslationVector<Data>
  {
    public:
      SimpleTranslationVector4(const Data x, const Data y, const Data z, const Data w) :
        SimpleVector4<Data> (x, y, z, w)
      {
      }
  };

template<class Data = float>
  class Matrix
  {
    // All pure virtual functions.
  };

template<class Data>
  class TransformationMatrix : public virtual Matrix<Data>
  {
    // All pure virtual functions.

    virtual void
    translate(TranslationVector<Data>* const translation) = 0;
  };

template<class Data>
  class SimpleMatrix44 : public virtual Matrix<Data>
  {
    public:
      SimpleMatrix44()
      {
        fData = new vector<Data> (CELLS_IN_MATRIX, 0);

        setIdentity();
      }

      vector<Data>*
      getData()
      {
        return (fData);
      }

      void
      setIdentity()
      {
        fData->at(0) = 1;
        fData->at(1) = 0;
        fData->at(2) = 0;
        fData->at(3) = 0;

        fData->at(4) = 0;
        fData->at(5) = 1;
        fData->at(6) = 0;
        fData->at(7) = 0;

        fData->at(8) = 0;
        fData->at(9) = 0;
        fData->at(10) = 1;
        fData->at(11) = 0;

        fData->at(12) = 0;
        fData->at(13) = 0;
        fData->at(14) = 0;
        fData->at(15) = 1;
      }

    private:
      static const int CELLS_IN_MATRIX = 16;

      vector<Data>* fData;
  };

template<class Data>
  class SimpleTransformationMatrix44 : public SimpleMatrix44<Data> , public TransformationMatrix<Data>
  {
    public:
      SimpleTransformationMatrix44() :
        SimpleMatrix44<Data> ()
      {
      }

      void
      translate(TranslationVector<Data>* translation)
      {
        vector<Data> *data = SimpleMatrix44<Data>::getData();
        vector<Data> *transData = ((SimpleVector4<Data>*) translation)->getData();

        // The error occurs on this line:
        data->at(12) += data->at(0) * transData->at(0) + data->at(4) * transData->at(1) + data->at(8) * transData->at(2);
        data->at(13) += data->at(1) * transData->at(0) + data->at(5) * transData->at(1) + data->at(9) * transData->at(2);
        data->at(14) += data->at(2) * transData->at(0) + data->at(6) * transData->at(1) + data->at(10) * transData->at(2);
        data->at(15) += data->at(3) * transData->at(0) + data->at(7) * transData->at(1) + data->at(11) * transData->at(2);
      }
  };

int
main(int argc, char** argv)
{
  SimpleTransformationMatrix44<float> matrix1;
  matrix1.translate(new SimpleTranslationVector4<float> (0.0f, 10.0f, 0.0f, 1.0f));

  return 0;
}

I have commented in the code where the error occurs. From debugging I can see that it actually occurs in the size() function of vector and that transData has not been initialized. I can’t for the life of me figure out why transData has not been initialized! Any ideas?

Thanks,

Gaz.

  • 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-23T16:21:05+00:00Added an answer on May 23, 2026 at 4:21 pm

    You’re doing a C-style cast between unrelated types. This is not safe. The fact that you need to do this at all probably indicates a problem in your design, but try replacing this:

    vector<Data>* transData = ((SimpleVector4<Data>*) translation)->SimpleVector4<Data>::getData();

    with this:

    vector<Data>* transData = dynamic_cast<SimpleVector4<Data>*>(translation)->getData();

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

Sidebar

Related Questions

I have a relatively big SSIS package which I'm trying to edit. I basically
I have a config file that I want to basically edit the uncommented lines,
EDIT: I am basically running into the following documented issue . I am using
I'm trying to load a page that is basically an edit form inside a
Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: From another question I provided an answer that has links to a lot
EDIT: This question is more about language engineering than C++ itself. I used C++
Edit: Basically what I need is for visual studio to always rebuild all when
I'm using Visual Studio 2008 and I have been wondering why doesn't the autocompletion
I am wondering if something like this could be done(of course what I have

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.