1

I am new to c++ but I am working on a project dealing with doing different operations with sets and one of them simply prints it out if the set is finite. SoS is the object being used which just stands for set of strings and has a vector of strings and a boolean as its data members. I created a function to check if the set is finite and I am trying to call it in my print function but i keep getting an error saying "no member named "isFinite." Heres what I have, any help is greatly appreciated.

void SoS::print() const{
    if (m_vos.isFinite() == true){
        for (int i = 0; i < m_vos.size(); i++){
            cout << m_vos[i]<< endl;
        }
    }
    else{
        cout << "COMPLEMENT OF:"<< endl;
        for (int i = 0; i< m_vos.size(); i++){
            cout << m_vos[i]<< endl;
        }
    }
}

bool SoS::isFinite() const{
    if (isfinite(m_vos.size()){
        return true;
    }
    return false;
}
9
  • Is it saying no member named "isFinite" or is it saying no member named "isfinite"? In your isFinite method you make a call to isfinite. Also isFinite doesn't have any parameters. And if your first line of a method calls said method, you'll get an infinite recursion. Commented Oct 15, 2015 at 4:08
  • What is m_vos? It looks like a member of SoS but doesn't appear to be a pointer. You need to call SoS::isFinite() on an object of SoS, or you can call it from within another method of SoS. Commented Oct 15, 2015 at 4:09
  • @Tas m_vos could be a value-member, not all objects need pointers to use them. Commented Oct 15, 2015 at 4:10
  • But in order for it to be of type SoS, declared in SoS, it would need to be a pointer right? Unless it was a global? Commented Oct 15, 2015 at 4:11
  • @Tas The OP wrote that SoS contains a "vector of strings and a boolean as its data members". So vector<string> m_vos; Commented Oct 15, 2015 at 4:11

2 Answers 2

4

C++, like C, requires forward declaration due to the nature of its single-pass compiler design. In C++ this isn't usually a problem as a class is fully declared in the header file before the .cpp file, but that error message suggests you haven't fleshed-out your class declaration.

It should look like this (according to your description):

class SoS {
private:
    vector<string> m_vos;
    bool someBool;
public:
    void print() const;
    bool isFinite() const;
}
Sign up to request clarification or add additional context in comments.

5 Comments

OP will also need bool isfinite(param) in his header file as well, unless it's declared globally or in the same namespace.
@JonnyHenly Not necessarily, isinfinite could be a global function.
If m_vos is indeed a std::vector<std::string>, it would be an error to call m_vos.isFinite(), so the problem would be "no member named isFinite()" in std::vector
@Tas Ah, I missed that call at the beginning of the print function. I don't know. We'll have to wait until the OP gives more details.
isfinite within my isFinite function is coming from #include <math.h>.
0

The problem is that you are attempting to call SoS::isFinite() on a std::vector<std::string> (m_vos). std::vector has no such member. You can only call SoS::isFinite() on an object of type SoS or within a SoS function.

Fortunately you are within a SoS function, so you can simply change your code to:

void SoS::print() const{
    // Calls SoS::isFinite()
    if (isFinite() == true){

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.