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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:59:11+00:00 2026-05-26T12:59:11+00:00

I am trying to cerate my own class with boost::adjacency_matrix graph as a member,

  • 0

I am trying to cerate my own class with boost::adjacency_matrix graph as a member, but I am stuck on compilation error. Sample class that won’t compile:

namespace zto {

typedef boost::adjacency_matrix<boost::undirectedS> Graph;

class SampleClass
{
public:
    Graph g;
    SampleClass();
};

And the compilation error:

./src/sample.cpp: In constructor ‘zto::SampleClass::SampleClass()’:
./src/sample.cpp:27:31: error: no matching function for call to 
  ‘boost::adjacency_matrix<boost::undirectedS>::adjacency_matrix()’
./src/sample.cpp:27:31: note: candidates are:
/usr/include/boost/graph/adjacency_matrix.hpp:622:5: note: template<class EdgeIterator, 
  class EdgePropertyIterator> boost::adjacency_matrix::adjacency_matrix(EdgeIterator, 
  EdgeIterator, EdgePropertyIterator, boost::adjacency_matrix<Directed, VertexProperty, 
  EdgeProperty, GraphProperty, Allocator>::vertices_size_type, const GraphProperty&)
/usr/include/boost/graph/adjacency_matrix.hpp:604:5: note: template<class EdgeIterator> 
  boost::adjacency_matrix::adjacency_matrix(EdgeIterator, EdgeIterator, 
  boost::adjacency_matrix<Directed, VertexProperty, EdgeProperty, GraphProperty, 
  Allocator>::vertices_size_type, const GraphProperty&)
/usr/include/boost/graph/adjacency_matrix.hpp:593:5: note: 
  boost::adjacency_matrix<Directed, VertexProperty, EdgeProperty, GraphProperty, 
  Allocator>::adjacency_matrix(boost::adjacency_matrix<Directed, VertexProperty, 
  EdgeProperty, GraphProperty, Allocator>::vertices_size_type, const GraphProperty&) 
  [with Directed = boost::undirectedS, VertexProperty = boost::no_property, EdgeProperty 
  = boost::no_property, GraphProperty = boost::no_property, Allocator = 
  std::allocator<bool>, boost::adjacency_matrix<Directed, VertexProperty, EdgeProperty, 
  GraphProperty, Allocator>::vertices_size_type = unsigned int]
/usr/include/boost/graph/adjacency_matrix.hpp:593:5: note:   candidate expects 2 
  arguments, 0 provided
/usr/include/boost/graph/adjacency_matrix.hpp:474:9: note: 
  boost::adjacency_matrix<boost::undirectedS>::adjacency_matrix(const 
  boost::adjacency_matrix<boost::undirectedS>&)
/usr/include/boost/graph/adjacency_matrix.hpp:474:9: note:   candidate expects 1 
  argument, 0 provided

It looks like that compilator thinks Graph is a function?!

Can anybody tell me, how to declare boost::adjacency_matrix as a member of my class?

  • 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-26T12:59:11+00:00Added an answer on May 26, 2026 at 12:59 pm

    The object member of your class is intitialized using a default constructor if you don’t specify anything else as initializer. It seems that adjacency_matrix does not have a default constructor.

    You should do something like this instead:

    typedef boost::adjacency_matrix Graph;

    class SampleClass
    {
    public:
        Graph g;
        SampleClass(size_t arg)
        : g(arg) // this is important
        {
          // As before, can also be in a cpp. 
          // It is just important that the initializer is used.
        }
    
    };
    

    Of course, in practice you could also make use of the other constructor arguments, use you won defaults, etc. This should just be a very simple example. I have never used boost::adjecency_matrix so I don’t know about good practice and what actually makes sense. I just took this from the error message.

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

Sidebar

Related Questions

I'm trying to create my own custom validator class that I can check the
I'm trying to create my own Vector2D class, similar to that of XNA's, to
I'm trying to create my own class to manage matrixes, but I'm a newbie
I'm trying to create my own templated List class as a practice excercise. I
I'm trying to create my own template for a List class as a learning
I am trying to create my own torrent tracker but dont know how to
I'm trying to create my own plugin. But I'm having trouble getting things right.
I'm trying to create my own subclass of socket.socket that will be able to
I am trying to create my own datatype that is like a vector or
I'd like to create my own class extending array of ints. Is that possible?

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.