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 8959441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:26:22+00:00 2026-06-15T15:26:22+00:00

When I compile the following, #include <boost/numeric/ublas/vector.hpp> #include <iomanip> #include <stdio.h> namespace ublas =

  • 0

When I compile the following,

#include <boost/numeric/ublas/vector.hpp>
#include <iomanip>
#include <stdio.h>

namespace ublas = boost::numeric::ublas;

template <class T> class Vector
{
    private:

       ublas::vector<T> m_ublas_vec;
       unsigned m_size;

    public:

       Vector(unsigned s){
          m_size = s;
          m_ublas_vec.resize(m_size);
       }

       T &operator () (unsigned idx) {
          if(idx >= m_size){
             perror("ERROR: Index out of bounds!\n");
             exit(1);
          }
          return m_ublas_vec(idx);
       }

       // Right-multiply by scalar.
       template <class TT, class S>
       friend Vector<TT> operator * (const Vector<TT> &, S);

       // Left multiply by scalar.
       template <class TT, class S>
       friend Vector<TT> operator * (S, const Vector<TT> &);
};

template <class T, class S>
Vector<T> Vector<T>::operator * (const Vector<T> &v_in, S scalar){
   Vector<T> v_out (v_in.m_size);
   v_out.m_ublas_vec = v_in.m_ublas_vec*static_cast<T>(scalar);
   return v_out;
}

template <class T, class S>
Vector<T> Vector<T>::operator * (S scalar, const Vector<T> &v_in){
   Vector<T> v_out (v_in.m_size);
   v_out.m_ublas_vec = v_in.m_ublas_vec*static_cast<T>(scalar);
   return v_out;
}

I get this error:

vector_test.cpp:49:95: error: invalid use of incomplete type 'class Vector'

vector_test.cpp:7:26: error: declaration of 'class Vector'

What am I doing wrong?

  • 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-06-15T15:26:23+00:00Added an answer on June 15, 2026 at 3:26 pm

    You friend functions don’t declare member functions. So, you want to define them as

    template <class T, class S>
    Vector<T> operator * (const Vector<T> &v_in, S scalar){
       Vector<T> v_out (v_in.m_size);
       v_out.m_ublas_vec = v_in.m_ublas_vec*static_cast<T>(scalar);
       return v_out;
    }
    
    template <class T, class S>
    Vector<T> operator * (S scalar, const Vector<T> &v_in){
       Vector<T> v_out (v_in.m_size);
       v_out.m_ublas_vec = v_in.m_ublas_vec*static_cast<T>(scalar);
       return v_out;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: #include <boost/smart_ptr/shared_ptr.hpp> #include <boost/numeric/interval.hpp> #include <boost/math/distributions/students_t.hpp> using namespace boost::numeric;
Please consider the following simplified example: #include boost/shared_ptr.hpp #include boost/smart_ptr/enable_shared_from_this.hpp using namespace boost; class
Consider the following code: #include <vector> #include <boost/noncopyable.hpp> struct A : private boost::noncopyable {
Trying to build the following simple example #include <boost/python.hpp> using namespace boost::python; tuple head_and_tail(object
I tried to compile the following code on ubuntu 11.04: #include <boost/interprocess/shared_memory_object.hpp> #include <iostream>
I have the following code which i m trying to compile: #include <boost/filesystem/convenience.hpp> #include
Consider the following code: #include <vector> #include <boost/variant.hpp> struct foo; typedef boost::variant<foo> bar; struct
I'm trying to compile the following snippet of code: #include <boost/filesystem/path.hpp> //Other includes snipped
The following code give compile error caused by line 17: #include <boost/bind.hpp> #include <boost/function.hpp>
I tried to compile this code: #include <boost/range/adaptors.hpp> #include <boost/range/algorithm.hpp> #include <vector> int main()

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.