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

The Archive Base Latest Questions

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

Possible Duplicate: Is this possible in C++? toString(ClassName* class) I’m trying to use toString

  • 0

Possible Duplicate:
Is this possible in C++? toString(ClassName* class)

I’m trying to use toString but I have a problem in there.
I ask this question second time, because the first time I asked before had insufficient information. I just worried about the length of question. Sorry about that.

toString is in the Animal class, and Animal class has vector<Treatment> treatArray; as a data member, but the thing is I can use the data member itself, but I cannot get the data member of treatArray. These are my code:

Animal.h

#ifndef ANIMAL_H
#define ANIMAL_H

#include "jdate.h"
//#include "Treatment.h"
#include <vector>
#include <sstream>

class Treatment;
class Animal{
protected:
    int id;
    double weight;
    int yy;
    int mm;
    int dd;
    double dose;
    double accDose;
    char sex;
    vector<Treatment*> treatArray;
public:
    Animal();
    Animal(int newid, double newweight, int yy, int mm, int dd, char newsex, vector<Treatment*> treatArray);
    ~Animal();

    void setTreatArray(vector<Treatment*> treatArray);
    vector<Treatment*> getTreatArray();

    string toString();
};

Treatment.h

#ifndef TREATMENT_H
#define TREATMENT_H
#include "jdate.h"

class Treatment{
private:
    int id;
    jdate dayTreated;
    double dose;
    double accDose;
public:
    Treatment(int id,jdate dayTreated, double dose);
    Treatment();
    ~Treatment();
};
#endif

Animap.cpp

#include "Animal.h"
//using namespace std;

Animal::Animal(int newid, double newweight, int yy, int mm, int dd, char newsex, vector<Treatment*> treatArray)
{
    id = newid;
    weight = newweight;
    yy = yy;
    mm = mm;
    dd = dd;
    dose = 0;
    accDose = 0;
    sex = newsex;
}

Animal::Animal()
{
    id = 0;
    weight = 0;
    yy = 0;
    mm = 0;
    dd = 0;
    dose = 0;
    accDose = 0;
    sex = ' ';
}

void Animal::setTreatArray(vector<Treatment*> treatArray){treatArray = treatArray;}
vector<Treatment*> Animal::getTreatArray(){return treatArray;}

string Animal::toString()
{
    jdate DOB(getYY(),getMM(),getDD());
    ostringstream ostr;
    ostr<<"Cattle / Sheep: "<<getSex()<<", Weight: "<<getWeight()
        <<" kg. DOB: " <<DOB.toString()<<" Accum Dose " <<getAccDose() << "mg" << endl;



if(getTreatArray().size()==0)
        ostr<<"\n      No History Found\n";
    else
    {
        for(int i=0;i<getTreatArray().size();i++)
        {
    //UNTIL HERE, NO ERROR FOUND, BUT ERROR OCCURS FROM THE STATEMENT BELOW
            ostr<<"   Treatment: " << getTreatArray().at(i)->getID() << "  "
                <<getTreatArray().at(i)->getDayTreated().toString()<<  "   "
                <<getTreatArray().at(i)->getDose() <<"mg\n";
        }
    }
     return ostr.str();
}

There are setter and getter for each class, and I cut it down.

Also, I thought it’s because of initalisation of the vector, but I googled regarding initalising vector, and it says that vector is automatically initialised, so I don’t have to initailise manually. Now I don’t know what the problem is 🙁
The error message is:

1   IntelliSense: pointer to incomplete class type is not allowed   l:\2011-08\c++\assignment\drug management\drug management\animal.cpp    97  30  Drug Management
  • 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-26T02:11:08+00:00Added an answer on May 26, 2026 at 2:11 am

    You should include Treatment.h in Animal.cpp.

    EDIT: To expand on the reason, the error message translates to:

    “I see that you’ve declared a class called Treatment. But I don’t see its implementation!”.

    So to let the compiler see its implementation where you’re accessing the members of the class Treatment, you need to #include Treatment.h in your Animal.cpp. I see the reason why you don’t want it to be in Animal.h, because Animal.h is being included in Treatment.h, which could cause compiler to get into a problem like:

    “Okay! I’m parsing Animal.cpp…
    – It includes Animal.h…
    — I’m going to expand Animal.h…
    — Animal.h includes Treatment.h…
    — I’m going to expand Treatment.h…
    — Treatment.h includes Animal.h…
    —- I’m going to expand Animal.h….
    —- (Loops)”

    This kind of gets avoided by the #pragma once or #ifdef guards. But when them come into action, compiler goes like this:

    “Okay! I’m parsing Animal.cpp…
    – It includes Animal.h…
    — I’m going to expand Animal.h…
    — Animal.h includes Treatment.h…
    — I’m going to expand Treatment.h…
    — Treatment.h is using class called Animal…
    — WHERE IS THE DEFINITION FOR ANIMAL?…. ERROR!
    — (The compiler did not come to the point where class Animal was defined!)

    It will also depend on whether the compiler started with Treatment.cpp or Animal.cpp. If it was Treatment.cpp, it would complain about missing definition of Treatment (just the opposite scenario of what’s happened with Animal).

    Now that you’ve declared to the compiler in Animal.h that “Keep an eye out for a class called Treatment”, as long as it’s not being used in Animal.h and the use of Treatment class is as a pointer, the compiler will not complain with the header file side of Animal class. But in Animal.cpp you’re calling a function from Treatment class. Then the compiler goes:

    Hey! You told me to look out for a class called Treatment. And now you’re asking me to resolve that function definition, but I don’t see the implementation of Treatment!

    And hence the reason to include Treatment.h in your Animal.cpp. Animal.cpp will get compiled independently of Treatment.cpp and vice-versa and hence should not cause the clash I mentioned above.

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

Sidebar

Related Questions

Possible Duplicate: Difference between Convert.tostring() and .tostring() Hi Carrying on from this question What
Possible Duplicate: PHP ToString() equivalent I get this error: Catchable fatal error: Object of
Possible Duplicate: Is this possible to use lwuit.Dialog with javax.microedition.lcdui.Canvas in wireless toolkit 2.5.2?
Possible Duplicate: Why does this intentionally incorrect use of strcpy not fail horribly? Below
Possible Duplicate: How Do I Access This Variable? Lets say I have the code:
Possible Duplicate: (String) or .toString()? I have an Object. Is it better to do
Possible Duplicate: C# Double - ToString() formatting with two decimal places but no rounding
Possible Duplicate: Simple division I juz wanna ask how to represent this kind of
Possible Duplicate: How Random is System.Guid.NewGuid()? Based on this question I would like to
Possible Duplicate: Question on this JavaScript Syntax (“What Does This Do?”) in this article

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.