Question

i have this error in the title: here class declaration of variables and prototypes of function

#ifndef ROZKLADLICZBY_H
#define ROZKLADLICZBY_H


class RozkladLiczby{
public:
    RozkladLiczby(int);                  //konstruktor
    vector<int> CzynnikiPierwsze(int); //metoda
    ~RozkladLiczby();
};  


#endif

And class body:

#include "RozkladLiczby.h"
using namespace std;
#include <iostream>
#include <vector>




RozkladLiczby::~RozkladLiczby()         //destruktor
{}

RozkladLiczby::RozkladLiczby(int n){
int* tab = new int[n+1];
int i,j;

for( i=0;i<=n;i++)
    tab[i]=0;                  //zerujemy tablice

for( i=2;i<=n;i+=2)
    tab[i]=2;                  //zajmujemy sie liczbami parzystymi

for(i=3; i<=n;i+=2)
    for(j=i;j<=n;j+=i)         //sito erastotesa
        if(tab[j]==0)
            tab[j]=i;

}

   vector<int> RozkladLiczby::CzynnikiPierwsze(int m){
vector<int> tablica;
while(m!=1){
        tablica.push_back(tab[m]);
        m=m/tab[m];
}

return tablica;

}

Whats wrong with the prototype of function in first block? Why vector is told to be not a type? I would be grateful if u could help me to find out this.

Was it helpful?

Solution 2

Change your header file to:

#ifndef ROZKLADLICZBY_H
#define ROZKLADLICZBY_H
#include <vector>

class RozkladLiczby{
public:
    RozkladLiczby(int);                  //konstruktor
    std::vector<int> CzynnikiPierwsze(int); //metoda
    ~RozkladLiczby();
private:
    int* tab;
};  


#endif

OTHER TIPS

Your header file does not include the vector header. Add a #include <vector> to the beggining.

Besides, you should refer to it as std::vector<int> instead of vector<int>, since it belongs to the std namespace. Declaring using namespace x; in header files is not a good practice, as it will propagate to other files as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top