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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:48:26+00:00 2026-06-14T23:48:26+00:00

I have class Student ( studentOwner ) and class Section . Here is my

  • 0

I have class Student (studentOwner) and class Section.
Here is my class Student:

class Student {
  vector<Section*> enrolledSections;
public:
  vector<Section*> getEnrolledSections() const { return enrolledSections; }
}

So, when I get vector<Section*> and assign to another vector, I will meet error. I’m using Microsoft Visual Studio.

// first example: no error, if take size of vector
int a = studentOwner->getEnrolledSections().size();
// second example: error, when only take its vector and assign again
// Error: no suitable user-define conversion from "std::vector<error-type" ....
vector<Section*> enrolled = studentOwner->getEnrolledSections();
// third example: error when take this vector and assign to reference of same type
// Error: initial value of reference to non-const value must be lvalue
vector<Section*>& enrolled = studentOwner->getEnrolledSections();

Full error at second example is:

Error: no suitable user-define conversion from "std::vector<error-type", std::alocator<<error-type> *>> "to " std::vector<Section*, std::allocator<Section*>>" exists

In many class of my project, I cannot do line two and line three and received same error. I cannot explain by myself. Please teach me at this point.

Thanks 🙂

  • 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-14T23:48:27+00:00Added an answer on June 14, 2026 at 11:48 pm

    Usually if you see error-type in MSVC errors, it’s a result of a forward declared type that wasn’t included in time for that compilation unit. For example,

    // Course.h
    class Student;
    
    class Course {
         [...]
    public:
         Student* getStudent();
    }
    
    // Course.cpp
    #include "Course.h"
    
    Student* Course::getStudent()
    {
        return new Student("Name");  //< Whoops, we never included Student.h!
    }
    

    In the comments you indicate a circular include dependency. As @Daniel Castro noted, you should forward declare in your header files to avoid the circular includes, then include the needed header files in your .cpp files (note the forward declaration class Student; above if you’re not familiar).

    As an aside, I would also note some design issues with your example. Returning std::vector<Section*> doesn’t tell much about who owns what. If I get a std::vector by value from a function, the convention is that I now own the vector and its contents. If I own something, then I’m responsible for deleting it. Without seeing your actual implementation, most coders would be surprised to learn they shouldn’t delete the contents of the vector. I would suggest either returning the vector by const& (eg, const vector<Section*>&) which prevents client code from manipulating the vector (so clients don’t own it), or using std::shared_ptr to manage a shared ownership scheme of your Section objects:

    class Student {
        vector<shared_ptr<Section>> enrolledSections_;
    public:
        vector<shared_ptr<Section>> getEnrolledSections() const { return enrolledSections_; }
    }
    

    Now it’s clear who owns what. More than you were asking for, but hopefully it helps.

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

Sidebar

Related Questions

I have class Student { public List<Degree> Degrees {get;set;} } class Degree { public
I have the following classes: public class Student { public string StudentID { get;
i have these models: public class Student { public int Id { get; set;
I have class student : public class Student { public string Name { get;
I have a class student: public class Student { public int StudentId{get;set;} public string
I have Class and Student objects. Both have collection of another as property. Which
I have a Student class in my application as below: public class Student {
I have a simple class Student under namespace School. namespace XmlTestApp { public class
I have created a class student with three properties like this public class Student
Suppose I have an abstract class Person . There is another class Student which

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.