I want to display the objects of the class and the number of objects by using a static function. I typed this code but it does not work. It gives an error Too many types indeclaration" and "undefined symbol getCount. Can anyone help me? where is actually error in this code?
#include<iostream>
#include<string>
class Bag {
private:
static int objectCount;
int Weight;
std::string Brand;
std::string Type;
std::string Material;
std::string Colour;
public:
Bag(int W, std::string B, std::string T, std::string M, std::string C) {
Weight = W;
Brand = B;
Type = T;
Material = M;
Colour = C;
objectCount++;
}
void print() {
std::cout << "\n";
std::cout << "Bag: \n\n";
std::cout << "Weight:\t\t" << Weight << "kg" << '\n';
std::cout << "Brand:\t\t" << Brand << '\n' << "Type:\t\t" << Type << '\n';
std::cout << "Material:\t" << Material << '\n' << "colour:\t\t" << Colour << std::endl;
}
static int getCount() {
return objectCount;
}
};
int Bag::objectCount = 0;
int main() {
Bag bag_1(2, "Slazanger", "Atheletic Bag", "Polyethylene", "Brown");
bag_1.print();
std::cout << "object count " << Bag::getCount() << '\n';
Bag bag_2(4, "Samsonite", "Travel Bag", "Synthetic Fibre", "Gray");
bag_2.print();
std::cout << "object count " << Bag::getCount() << '\n';
Bag bag_3(5, "Herschel", "Duffel bag", "Leather", "Black");
bag_3.print();
std::cout << "object count " << Bag::getCount() << '\n';
Bag bag_4(3, "Kewin Woods", "Hand Bag", "Fibre", "Blue");
bag_4.print();
std::cout << "object count " << Bag::getCount() << std::endl;
while(!std::cin.get());
return 0;
}
You are scoping it incorrectly, getCount is statically scoped to the translation
unit, not the class. Thus it has no symbol named objectCount available to it.
To fix it, merely put the method inside the class.
class Bag {
private:
static int objectCount;
int Weight;
string Brand,Type,Material,Colour;
public:
Bag(int W ,string B ,string T,string M,string C)
{
Weight=W;
Brand=B;
Type=T;
Material=M;
Colour=C;
objectCount++;
}
void print()
{
cout<<"\n";
cout<<"Bag: \n\n";
cout<<"Weight:\t\t"<<Weight<<"kg"<<endl;
cout<<"Brand:\t\t"<<Brand<<endl<<"Type:\t\t"<<Type<<endl;
cout<<"Material:\t"<<Material<<endl<<"colour:\t\t"<<Colour<<endl;
}
static int getCount()
{
cout<< objectCount;
}
};
Aditionally, Borland is a really old compiler and suprised to even still
hear it's name, last release was around 15 years ago so you should really
consider using clang, gcc or msvc and upgrading your learning materials to
something less ancient. There has been alot of evolution in terms of practices,
standards and compiler conformance.
For example, C++ headers don't have an extension, and other small things like that.
This is a working version of your code:
#include <iostream>
#include <cstring>
using namespace std;
class Bag {
private:
static int objectCount;
int Weight;
string Brand, Type, Material, Colour;
public:
Bag(int W, string B, string T, string M, string C) //constructor
{
Weight = W;
Brand = B;
Type = T;
Material = M;
Colour = C;
objectCount++;
}
void print() {
cout << "\n";
cout << "Bag: \n\n";
cout << "Weight:\t\t" << Weight << "kg" << endl;
cout << "Brand:\t\t" << Brand << endl << "Type:\t\t" << Type << endl;
cout << "Material:\t" << Material << endl << "colour:\t\t" << Colour
<< endl;
}
static int getCount() //static function to count objects
{
cout << objectCount;
};
};
int Bag::objectCount = 0;
int main() {
Bag bag_1(2, "Slazanger", "Atheletic Bag", "Polyethylene", "Brown");
Bag bag_2(4, "Samsonite", "Travel Bag", "Synthetic Fibre", "Gray");
Bag bag_3(5, "Herschel", "Duffel bag", "Leather", "Black");
Bag bag_4(3, "Kewin Woods", "Hand Bag", "Fibre", "Blue");
bag_1.print();
cout << "object count" << Bag::getCount();
bag_2.print();
cout << "object count" << Bag::getCount();
bag_3.print();
cout << "object count" << Bag::getCount();
bag_4.print();
cout << "object count" << Bag::getCount();
}
There were several mistakes in the version you posted:
in C++ you don't need the .h when including files
you were using cout without the std:: qualifier or adding using namespace std; to your source. Also, please read this.
your static function was not declared/defined inside your class definition
it should be int main instead of void main
One last note: I removed your #include <conio.h> which should probably read #include <conio> and getch because I compiled this on a linux machine. Feel free to add them back in if you want them.
Related
For some reason I cannot use functions attached to the object I want to use. I added a comment to the line that is not working. As an error I get "Error; pointer to incomplete class type is not allowed" Please help
This is code in dokter.ccp
int counter = 0;
for (list<Wielrenner*>::iterator it = wielrenners.begin(); it != wielrenners.end(); it++){
Wielrenner* wielrennerOB = *it;
cout << "\nID: " << counter;
cout << "List size: " << persons.size() << endl;
wielrennerOB->print(); // This is not working
counter++;
}
This is code in wielrenner.h
#ifndef WIELRENNER_H_
#define WIELRENNER_H_
//#include <fstream>
#include "persoon.h"
#include "Onderzoek.h"
class Wielrenner :
public Persoon
{
public:
Wielrenner(string, string, Adres, string, Datum, Datum, string, int, float, float, float,list<Onderzoek>* );
~Wielrenner(void);
int getLengte() const;
float getGewicht() const;
float getVo2max() const;
float getMaxVermogen() const;
list<Onderzoek> getOnderzoekenList();
void setLengte(int);
void setGewicht(float);
void setVo2max(float);
void setMaxVermogen(float);
void voegOnderzoekToeList(Onderzoek);
void showOnderzoeksList();
void setOnderzoeksLijst(list<Onderzoek>&);
void print();
void printFile(ofstream&);
private:
int lengte;
float gewicht;
float vo2max;
float maxVermogen;
list<Onderzoek> onderzoeken;
};
#endif /* WIELRENNER_H_ */
code in wielrenner.CCP
using namespace std;
#include <string>
#include "Wielrenner.h"
/*
#include "Onderzoek.h"
*/
Wielrenner::Wielrenner(string voornaam, string achternaam, Adres adres, string telefoon, Datum datumInDienst, Datum geboorteDatum,
string persoonType, int lengte, float gewicht, float vo2max, float maxVermogen,list<Onderzoek>* onderzoeken)
: lengte(lengte),
gewicht(gewicht),
vo2max(vo2max),
maxVermogen(maxVermogen),
Persoon(voornaam, achternaam, adres, telefoon, datumInDienst, geboorteDatum, persoonType)
{
}
Wielrenner::~Wielrenner(void)
{
}
//setten van gegevens
void Wielrenner::setLengte(int newLengte){
lengte = newLengte;
}
void Wielrenner::setGewicht(float newGewicht){
gewicht = newGewicht;
}
void Wielrenner::setVo2max(float newVo2max){
vo2max = newVo2max;
}
void Wielrenner::setMaxVermogen(float newMaxVermogen){
maxVermogen = newMaxVermogen;
}
void Wielrenner::voegOnderzoekToeList(Onderzoek newOnderzoek){
onderzoeken.push_back(newOnderzoek);
}
void Wielrenner::showOnderzoeksList(){
int teller=0;
for (list<Onderzoek>::iterator it = onderzoeken.begin(); it != onderzoeken.end(); it++){
Onderzoek onderzoekOB = *it;
cout << teller << " - ";
onderzoekOB.print();
teller++;
}
}
void Wielrenner::setOnderzoeksLijst(list<Onderzoek>& newOnderzoeksLijst){
onderzoeken = newOnderzoeksLijst;
}
void Wielrenner::print(){
cout << "(" << persoonID << ") Persoon: " << endl;
cout << persoonType << endl;
cout << voornaam << " " << achternaam << endl;
adres.print();
cout << telefoon << endl;
cout << "Datum in dienst: ";
datumInDienst.print();
cout << "Geboortedatum: ";
geboorteDatum.print();
cout << "> Extra wielrenner gegevens: " << endl;
cout << "Lengte: " << lengte << endl;
cout << "Gewicht: " << gewicht << endl;
cout << "vo2max: " << vo2max << endl;
cout << "maxVermogen: " << maxVermogen << endl;
}
void Wielrenner::printFile(ofstream &myfile){
myfile << persoonID << "\n";
myfile << persoonType << "\n";
myfile << voornaam << " " << achternaam << "\n";
adres.printFile(myfile);
myfile << telefoon << "\n";
datumInDienst.printFile(myfile);
geboorteDatum.printFile(myfile);
myfile << lengte << "\n";
myfile << gewicht << "\n";
myfile << vo2max << "\n";
myfile << maxVermogen << "\n";
}
// returnen van gegevens
int Wielrenner::getLengte() const{
return lengte;
}
float Wielrenner::getGewicht() const{
return gewicht;
}
float Wielrenner::getVo2max() const{
return vo2max;
}
float Wielrenner::getMaxVermogen() const{
return maxVermogen;
}
list<Onderzoek> Wielrenner::getOnderzoekenList(){
return onderzoeken;
}
An "incomplete class" is one declared but not defined. E.g.
class Wielrenner;
as opposed to
class Wielrenner
{
/* class members */
};
You need to #include "wielrenner.h" in dokter.ccp
One thing to check for...
If your class is defined as a typedef:
typedef struct myclass { };
Then you try to refer to it as struct myclass anywhere else, you'll get Incomplete Type errors left and right. It's sometimes a mistake to forget the class/struct was typedef'ed. If that's the case, remove "struct" from:
typedef struct mystruct {}...
struct mystruct *myvar = value;
Instead use...
mystruct *myvar = value;
Common mistake.
You get this error when declaring a forward reference inside the wrong namespace thus declaring a new type without defining it. For example:
namespace X
{
namespace Y
{
class A;
void func(A* a) { ... } // incomplete type here!
}
}
...but, in class A was defined like this:
namespace X
{
class A { ... };
}
Thus, A was defined as X::A, but I was using it as X::Y::A.
The fix obviously is to move the forward reference to its proper place like so:
namespace X
{
class A;
namespace Y
{
void func(X::A* a) { ... } // Now accurately referencing the class`enter code here`
}
}
The problem also occurs when header files are not included explicitly where they are needed, but implicitly through other heading files.
I came accross the same problem and solved it by checking my #includes.
If you use QKeyEvent you have to make sure that you also include it.
I had a class like this and my error appeared when working with "event"in the .cpp file.
myfile.h
#include <QKeyEvent> // adding this import solved the problem.
class MyClass : public QWidget
{
Q_OBJECT
public:
MyClass(QWidget* parent = 0);
virtual ~QmitkHelpOverlay();
protected:
virtual void keyPressEvent(QKeyEvent* event);
};
Check out if you are missing some import.
I was shown this code, and it compiles. No surprises there, but why was it organized the way it was? Why is there no class.cpp?
(Edit: I don't mean in terms of whitespace, I mean in terms of placement.)
/// main.cpp ///
#include <iostream>
#include "class.h"
int main() {
Pet a(4);
double x;
std::cout << "How much does this weigh? "; std::cin >> x;
Pet b(x);
Pet c(b);
std::cout << "You have " << a.getTotal() << " pets." << std::endl;
std::cout << "a weighs " << a.getWeight() << " pounds." << std::endl;
std::cout << "b weighs " << b.getWeight() << " pounds." << std::endl;
std::cout << "c weighs " << c.getWeight() << " pounds." << std::endl;
return 0;
}
/// class.h ///
#ifndef CLASS_H_
#define CLASS_H_
class Pet {
private:
double weight;
static int total;
public:
Pet() { weight = 0; upTotal(); }
Pet(double w) { weight = w; upTotal(); }
Pet(const Pet& that) { this->weight = that.weight; upTotal(); }
double getWeight() { return weight; }
void setWeight (double w) { weight = w; }
int getTotal() { return total; }
void upTotal() { ++total; }
void downTotal() { --total; }
};
int Pet::total = 0;
#endif // CLASS_H_
I was told that it is good practice to separate class declarations into header files and leave the insides for a source file. But here these functions are being defined in the header file instead of just being declared.
I didn't think much else of it after that, until I looked into a header file belonging to an IDE for GUIs, and I see lots of class methods being organized the same exact way. Why is this?
First off: I know that it is generally a bad idea to change an object's class, but I'm implementing my own programming language, and it has variables that can contain values of any type, and even change their type at will, so please assume I'm not a beginner not understanding OO basics.
Currently, I implement my variant variables in C. Each one has a pointer to a table of function pointers, containing functions like SetAsInt(), SetAsString() etc., followed by what would be instance variables in C++. All objects are the same size.
When a variable contains a string and someone assigns an Int to it, I manually call the destructor, change the table of function pointers to point to the table used for variadic int values, and then set its int instance variable.
This is a bit hard to maintain, as every time I add a new type, I have to add a new table of function pointers and fill out all the function pointers in it. Structs of function pointers seem to be very badly type-checked, and missing fields don't lead to complaints, so I can easily accidentally forget one pointer in the list and get interesting crashes. Also, I have to repeat all the function pointers that are the same in most types.
I'd like to implement my variadic types in C++ instead, where a lot of this type-checking and inheriting default behaviours is done for me by the compiler. Is there a safe way to do this?
PS - I know I could create a wrapper object and use new to allocate a new object, but I can't have the additional extra allocation overhead for every int variable on the stack.
PPS - The code needs to be portable across Linux, Mac, iOS and Windows for now, but if someone has a standard C++ solution, that would be even better.
PPPS - The list of types is extensible, but predetermined at compile-time. The base layer of my language defines just the basic types, but the host application my language is compiled into adds a few more types.
Usage Example:
CppVariant someNum(42); // Creates it as CppVariantInt.
cout << "Original int: " << someNum->GetAsInt()
<< " (" << someNum->GetAsDouble() << ")" << endl;
someNum->SetAsInt(700); // This is just a setter call.
cout << "Changed int: " << someNum->GetAsInt()
<< " (" << someNum->GetAsDouble() << ")" << endl;
someNum->SetAsDouble(12.34); // This calls destructor on CppVariantInt and constructor on CppVariantDouble(12.34).
cout << "Converted to Double: " << someNum->GetAsInt()
<< " (" << someNum->GetAsDouble() << ")" << endl; // GetAsInt() on a CppVariantDouble() rounds, or whatever.
(Imagine that beyond double and int, there would be other types in the future, like strings or booleans, but the caller of GetAsInt()/SetAsInt() shouldn't have to know what it is stored as, as long as it can be converted at runtime)
Here is a solution based on type-erasure, union and template specializations.
I'm not sure it fits your requirements.
Anyway, here is what it gets:
Anything is placed on the dynamic storage
No hierarchy required
You can easily improve it further to reduce the amount of code, but this aims to serve as a base point from which to start.
It follows a minimal, working example based on the intended use in the question:
#include<iostream>
class CppVariant {
union var {
var(): i{0} {}
int i;
double d;
};
using AsIntF = int(*)(var);
using AsDoubleF = double(*)(var);
template<typename From, typename To>
static To protoAs(var);
public:
CppVariant(int);
CppVariant(double);
int getAsInt();
double getAsDouble();
void setAsInt(int);
void setAsDouble(double);
private:
var data;
AsIntF asInt;
AsDoubleF asDouble;
};
template<>
int CppVariant::protoAs<int, int>(var data) {
return data.i;
}
template<>
int CppVariant::protoAs<double, int>(var data) {
return int(data.d);
}
template<>
double CppVariant::protoAs<int, double>(var data) {
return double(data.i);
}
template<>
double CppVariant::protoAs<double, double>(var data) {
return data.d;
}
CppVariant::CppVariant(int i)
: data{},
asInt{&protoAs<int, int>},
asDouble{&protoAs<int, double>}
{ data.i = i; }
CppVariant::CppVariant(double d)
: data{},
asInt{&protoAs<double, int>},
asDouble{&protoAs<double, double>}
{ data.d = d; }
int CppVariant::getAsInt() { return asInt(data); }
double CppVariant::getAsDouble() { return asDouble(data); }
void CppVariant::setAsInt(int i) {
data.i = i;
asInt = &protoAs<int, int>;
asDouble = &protoAs<int, double>;
}
void CppVariant::setAsDouble(double d) {
data.d = d;
asInt = &protoAs<double, int>;
asDouble = &protoAs<double, double>;
}
int main() {
CppVariant someNum(42);
std::cout << "Original int: " << someNum.getAsInt() << " (" << someNum.getAsDouble() << ")" << std::endl;
someNum.setAsInt(700);
std::cout << "Changed int: " << someNum.getAsInt() << " (" << someNum.getAsDouble() << ")" << std::endl;
someNum.setAsDouble(12.34);
std::cout << "Converted to Double: " << someNum.getAsInt() << " (" << someNum.getAsDouble() << ")" << std::endl;
}
On a lark, I tried using placement new to do this, and I have ... something ... It compiles, it does the job, but I'm not sure if it's an improvement over pure C. Since I can't have a union of C++ objects, I create a CPPVMAX() macro to pass the largest sizeof() of all subclasses as the size to mBuf[], but that's not really pretty either.
#include <iostream>
#include <string>
#include <cmath>
#define CPPVMAX2(a,b) (((a) > (b)) ? (a) : (b))
#define CPPVMAX3(a,b,c) CPPVMAX2((a),CPPVMAX2((b),(c)))
using namespace std;
class CppVariantBase
{
public:
CppVariantBase() { cout << "CppVariantBase constructor." << endl; }
virtual ~CppVariantBase() { cout << "CppVariantBase destructor." << endl; }
virtual int GetAsInt() = 0;
virtual double GetAsDouble() = 0;
virtual void SetAsInt( int n );
virtual void SetAsDouble( double n );
};
class CppVariantInt : public CppVariantBase
{
public:
CppVariantInt( int n = 0 ) : mInt(n)
{
cout << "CppVariantInt constructor." << endl;
}
~CppVariantInt() { cout << "CppVariantInt destructor." << endl; }
virtual int GetAsInt() { return mInt; }
virtual double GetAsDouble() { return mInt; }
virtual void SetAsInt( int n ) { mInt = n; }
protected:
int mInt;
};
class CppVariantDouble : public CppVariantBase
{
public:
CppVariantDouble( double n = 0 ) : mDouble(n)
{
cout << "CppVariantDouble constructor." << endl;
}
~CppVariantDouble()
{
cout << "CppVariantDouble destructor." << endl;
}
virtual int GetAsInt()
{
if( int(mDouble) == mDouble )
return mDouble;
else
return round(mDouble);
}
virtual double GetAsDouble() { return mDouble; }
virtual void SetAsDouble( int n ) { mDouble = n; }
protected:
double mDouble;
};
class CppVariant
{
public:
CppVariant( int n = 0 ) { new (mBuf) CppVariantInt(n); }
~CppVariant() { ((CppVariantBase*)mBuf)->~CppVariantBase(); }
operator CppVariantBase* () { return (CppVariantBase*)mBuf; }
CppVariantBase* operator -> () { return (CppVariantBase*)mBuf; }
protected:
uint8_t mBuf[CPPVMAX3(sizeof(CppVariantBase),sizeof(CppVariantInt),sizeof(CppVariantDouble))];
};
void CppVariantBase::SetAsInt( int n )
{
this->~CppVariantBase();
new (this) CppVariantInt(n);
}
void CppVariantBase::SetAsDouble( double n )
{
this->~CppVariantBase();
new (this) CppVariantDouble(n);
}
int main(int argc, const char * argv[]) {
CppVariant someNum(42);
cout << "Original int: " << someNum->GetAsInt()
<< " (" << someNum->GetAsDouble() << ")" << endl;
someNum->SetAsInt(700); // This is just a setter call.
cout << "Changed int: " << someNum->GetAsInt()
<< " (" << someNum->GetAsDouble() << ")" << endl;
someNum->SetAsDouble(12.34); // This changes the class to CppVariantDouble.
cout << "Converted to Double: " << someNum->GetAsInt()
<< " (" << someNum->GetAsDouble() << ")" << endl;
return 0;
}
So I have these classes:
In main I wrote an array of pointers:
student *arry[10];
How can I make each cell point to an object of a different class?
For example :
I want the cell 0 , 2 , 4
point to an object of class medstudent
using ( new statement )
thank you
here is class medStudent
#include<iostream>
#include"student.cpp"
using namespace std;
class medStudent:public student {
public :int clinicH;
public:
medStudent(int ch, string n , int i ):student(n,i){
setClinicH(ch);
cout << "New Medecine Student" << endl;
}
~medStudent(){
cout << "Medecine Student Deleted" << endl;
}
medStudent(medStudent & ms):student(ms){
cout << "New Copy Medecined Student" << endl;
}
medstudent(){
}
void setClinicH(int ch){
clinicH = ch;
}
int getClinicH()const{
return clinicH;
}
void print()const{
student::print();
cout << "Clinical Hours: " << getClinicH() << endl;
}
};
Here is class student:
#include <iostream>
//#include"medstudent.cpp"
using namespace std;
class student//:public medstudent
{
public :
static int numberOfSaeeds;
const int id;
string name;
public:
~student(){
cout << "Delete Student: " << getName() << " " << endl ;
}
student(string n, int i):id(i){
setName(n);
cout << "Student with args" << endl ;
}
void setName(string n){
name = n;
}
string getName()const{
return name;
}
void print()const{
cout << "My name is: " << name << endl;
cout << "My ID is: " << id << endl;
}
void setNOS(int nos){
numberOfSaeeds = nos;
}
int getNOS(){
return numberOfSaeeds;
}
void printAddress()const{
cout << "My address is " << this << endl;
}
student * getAddress(){
return this;
}
student(student & sc):id(sc.id){
name = sc.name;
setName(sc.getName());
cout << "New Object using the copy constructor" << endl;
}
};
Here is main code:
#include<iostream>
using namespace std;
#include"time.cpp"
#include "student.cpp"
//#include"medstudent.cpp"
int main(){
student a1("asa" , 2);
student * a[10];
a[3]= new student("jj", 22 );
a[0] = new medStudent();
}
Since you explicitly declare a medStudent constructor the compiler will not create a default constructor for your class. And when you do new medStudent(); you are (explicitly) trying to invoke the default constructor, which doesn't exist.
That will give you a build error, one that should have been very easy to diagnose if you read it and most importantly shown it to us (when asking questions about build errors, always include the complete and unedited error output, including any informational output, in the body of the question, together with the code causing the error).
The solution? Call the existing parameterized constructor. E.g. new medStudent("foo", 123).
By the way, if you want inheritance to work okay, and the base-class destructor to be called when deleting an object of a child-class, then you need to make the destructors virtual.
For some reason I cannot use functions attached to the object I want to use. I added a comment to the line that is not working. As an error I get "Error; pointer to incomplete class type is not allowed" Please help
This is code in dokter.ccp
int counter = 0;
for (list<Wielrenner*>::iterator it = wielrenners.begin(); it != wielrenners.end(); it++){
Wielrenner* wielrennerOB = *it;
cout << "\nID: " << counter;
cout << "List size: " << persons.size() << endl;
wielrennerOB->print(); // This is not working
counter++;
}
This is code in wielrenner.h
#ifndef WIELRENNER_H_
#define WIELRENNER_H_
//#include <fstream>
#include "persoon.h"
#include "Onderzoek.h"
class Wielrenner :
public Persoon
{
public:
Wielrenner(string, string, Adres, string, Datum, Datum, string, int, float, float, float,list<Onderzoek>* );
~Wielrenner(void);
int getLengte() const;
float getGewicht() const;
float getVo2max() const;
float getMaxVermogen() const;
list<Onderzoek> getOnderzoekenList();
void setLengte(int);
void setGewicht(float);
void setVo2max(float);
void setMaxVermogen(float);
void voegOnderzoekToeList(Onderzoek);
void showOnderzoeksList();
void setOnderzoeksLijst(list<Onderzoek>&);
void print();
void printFile(ofstream&);
private:
int lengte;
float gewicht;
float vo2max;
float maxVermogen;
list<Onderzoek> onderzoeken;
};
#endif /* WIELRENNER_H_ */
code in wielrenner.CCP
using namespace std;
#include <string>
#include "Wielrenner.h"
/*
#include "Onderzoek.h"
*/
Wielrenner::Wielrenner(string voornaam, string achternaam, Adres adres, string telefoon, Datum datumInDienst, Datum geboorteDatum,
string persoonType, int lengte, float gewicht, float vo2max, float maxVermogen,list<Onderzoek>* onderzoeken)
: lengte(lengte),
gewicht(gewicht),
vo2max(vo2max),
maxVermogen(maxVermogen),
Persoon(voornaam, achternaam, adres, telefoon, datumInDienst, geboorteDatum, persoonType)
{
}
Wielrenner::~Wielrenner(void)
{
}
//setten van gegevens
void Wielrenner::setLengte(int newLengte){
lengte = newLengte;
}
void Wielrenner::setGewicht(float newGewicht){
gewicht = newGewicht;
}
void Wielrenner::setVo2max(float newVo2max){
vo2max = newVo2max;
}
void Wielrenner::setMaxVermogen(float newMaxVermogen){
maxVermogen = newMaxVermogen;
}
void Wielrenner::voegOnderzoekToeList(Onderzoek newOnderzoek){
onderzoeken.push_back(newOnderzoek);
}
void Wielrenner::showOnderzoeksList(){
int teller=0;
for (list<Onderzoek>::iterator it = onderzoeken.begin(); it != onderzoeken.end(); it++){
Onderzoek onderzoekOB = *it;
cout << teller << " - ";
onderzoekOB.print();
teller++;
}
}
void Wielrenner::setOnderzoeksLijst(list<Onderzoek>& newOnderzoeksLijst){
onderzoeken = newOnderzoeksLijst;
}
void Wielrenner::print(){
cout << "(" << persoonID << ") Persoon: " << endl;
cout << persoonType << endl;
cout << voornaam << " " << achternaam << endl;
adres.print();
cout << telefoon << endl;
cout << "Datum in dienst: ";
datumInDienst.print();
cout << "Geboortedatum: ";
geboorteDatum.print();
cout << "> Extra wielrenner gegevens: " << endl;
cout << "Lengte: " << lengte << endl;
cout << "Gewicht: " << gewicht << endl;
cout << "vo2max: " << vo2max << endl;
cout << "maxVermogen: " << maxVermogen << endl;
}
void Wielrenner::printFile(ofstream &myfile){
myfile << persoonID << "\n";
myfile << persoonType << "\n";
myfile << voornaam << " " << achternaam << "\n";
adres.printFile(myfile);
myfile << telefoon << "\n";
datumInDienst.printFile(myfile);
geboorteDatum.printFile(myfile);
myfile << lengte << "\n";
myfile << gewicht << "\n";
myfile << vo2max << "\n";
myfile << maxVermogen << "\n";
}
// returnen van gegevens
int Wielrenner::getLengte() const{
return lengte;
}
float Wielrenner::getGewicht() const{
return gewicht;
}
float Wielrenner::getVo2max() const{
return vo2max;
}
float Wielrenner::getMaxVermogen() const{
return maxVermogen;
}
list<Onderzoek> Wielrenner::getOnderzoekenList(){
return onderzoeken;
}
An "incomplete class" is one declared but not defined. E.g.
class Wielrenner;
as opposed to
class Wielrenner
{
/* class members */
};
You need to #include "wielrenner.h" in dokter.ccp
One thing to check for...
If your class is defined as a typedef:
typedef struct myclass { };
Then you try to refer to it as struct myclass anywhere else, you'll get Incomplete Type errors left and right. It's sometimes a mistake to forget the class/struct was typedef'ed. If that's the case, remove "struct" from:
typedef struct mystruct {}...
struct mystruct *myvar = value;
Instead use...
mystruct *myvar = value;
Common mistake.
You get this error when declaring a forward reference inside the wrong namespace thus declaring a new type without defining it. For example:
namespace X
{
namespace Y
{
class A;
void func(A* a) { ... } // incomplete type here!
}
}
...but, in class A was defined like this:
namespace X
{
class A { ... };
}
Thus, A was defined as X::A, but I was using it as X::Y::A.
The fix obviously is to move the forward reference to its proper place like so:
namespace X
{
class A;
namespace Y
{
void func(X::A* a) { ... } // Now accurately referencing the class`enter code here`
}
}
The problem also occurs when header files are not included explicitly where they are needed, but implicitly through other heading files.
I came accross the same problem and solved it by checking my #includes.
If you use QKeyEvent you have to make sure that you also include it.
I had a class like this and my error appeared when working with "event"in the .cpp file.
myfile.h
#include <QKeyEvent> // adding this import solved the problem.
class MyClass : public QWidget
{
Q_OBJECT
public:
MyClass(QWidget* parent = 0);
virtual ~QmitkHelpOverlay();
protected:
virtual void keyPressEvent(QKeyEvent* event);
};
Check out if you are missing some import.