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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:34:31+00:00 2026-05-14T14:34:31+00:00

I have this main function: #ifndef MAIN_CPP #define MAIN_CPP #include dsets.h using namespace std;

  • 0

I have this main function:

#ifndef MAIN_CPP
#define MAIN_CPP

#include "dsets.h"
using namespace std;

int main(){
DisjointSets s;
s.uptree.addelements(4);
for(int i=0; i<s.uptree.size(); i++)
        cout <<uptree.at(i) << endl;
return 0;
}

#endif

And the following class:

class DisjointSets
   { 
public:
void addelements(int x);
int find(int x);
void setunion(int x, int y);

private:
vector<int> uptree;

};

#endif

My implementation is this:

void DisjointSets::addelements(int x){
        for(int i=0; i<x; i++)
        uptree.push_back(-1);


}

//Given an int this function finds the root associated with that node.

int DisjointSets::find(int x){
//need path compression

if(uptree.at(x) < 0)
        return x;
else
        return find(uptree.at(x));
}

//This function reorders the uptree in order to represent the union of two
//subtrees
void DisjointSets::setunion(int x, int y){

}

Upon compiling main.cpp (g++ main.cpp)

I’m getting these errors:

dsets.h: In function \u2018int main()\u2019:
dsets.h:25: error: \u2018std::vector > DisjointSets::uptree\u2019 is private

main.cpp:9: error: within this context

main.cpp:9: error: \u2018class std::vector >\u2019 has no member named \u2018addelements\u2019

dsets.h:25: error: \u2018std::vector > DisjointSets::uptree\u2019 is private

main.cpp:10: error: within this context

main.cpp:11: error: \u2018uptree\u2019 was not declared in this scope

I’m not sure exactly whats wrong.
Any help would be appreciated.

  • 1 1 Answer
  • 1 View
  • 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-14T14:34:31+00:00Added an answer on May 14, 2026 at 2:34 pm

    You can’t access a private element of a class from outside the class. Try making uptree public, or provide a means to access it through DisjointSets. Also, addelements() is a member of class DisjointSets, not vector uptree.

    #ifndef MAIN_CPP
    #define MAIN_CPP
    
    #include "dsets.h"
    using namespace std;
    
    int main(){
    DisjointSets s;
    s.uptree.addelements(4); // try s.addelements(4)
    for(int i=0; i<s.uptree.size(); i++) // try making uptree public
            cout <<uptree.at(i) << endl;
    return 0;
    }
    
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this .h file #ifndef VISUALSETTINGS_H #define VISUALSETTINGS_H #include <QPair> #include <QDataStream> class
I have this abstract base class ODESolver: //ODESolver.h #ifndef ODESolver_H #define ODESolver_H #include doublependulum.h
I have a TreeVertex class: // TreeVertex.h #ifndef __TREEVERTEX__ #define __TREEVERTEX__ #include <list> using
i have this files: //Q2a.h #ifndef Q2A_H #define Q2A_H inline int MyFactorial(int a) {
In the main view i have this function public function lang($file, $language){ require 'languages/'.$language.'/'.
I have a code like this $(document).ready(function(){ $(.add).bind ('click', function () { $('.main').append('<div class=add>Add
I have a JS code like this <script type=text/javascript> $(document).ready(function(){ $('.main').on('click', '.block', function (){
I have Javascript function defined in the main index.html file. One part of this
I have a jQuery function that replaces thumbnails with the main image. This is
This is the dependent class header #ifndef TransHeader #define TransHeader #include <string> #include CipherHeader.h

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.