I have a base class called Matrix which has a function transpose. I also have a derived class Matrix2 which is inherited publicly from Matrix

class Matrix
{
 public:
    Matrix();
    ...
    Matrix Transpose(void);
...
    };

class Matrix2 : public Matrix
    {
     public:
        Matrix2();
        ...
      };

In my main code, I tried this.

vector <Matrix2> myMatrix2;
vector <Matrix> *b = &myMatrix2;

to do this

b->transpose();

But I get the following error

error C2440: 'initializing' : cannot convert from 'std::vector<_Ty> *' to 'std::vector<_Ty> *'

What is wrong...

What is the way to access the transpose function from Matrix class in vector?

I get the following error.

error C2039: 'transpose' : is not a member of 'Matrix2'

Thanks

b is a pointer to a vector, not to a Matrix2. vector's don't have transpose() method.

myMtrix2[0].transpost() may be what you want. Or if you want to call that method for each Matrix2 in the vector

for(auto x : myMatrix2)
{
   x.transpost();
}

The above requires c++11 compiliant compiler, and iterates through each of the vector's objects.

write class matrix public top on portected.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.