jeudi 31 janvier 2019

How to make it work, problem with 2 classes

i have problem with my small project. I have two classes in it. Problem:

error: 'Display' was not declared in this scope

Display is a class. Here is code:

//main.cpp
#include <iostream>
#include "Display.h"
#include "Polynomial.h"

using namespace std;

int main()
{
    Polynomial prr;
    prr.show();
    cout<<endl;
    cout<<"Enter x= ";
    int x;
    cin>>x;
    cout<<endl;

    cout<<"value for x="<<x<<endl<<"y="<<prr.value(x);

    Display aa; // this doesn't work
    //abc.show();

    return 0;
}


//Display.h
#ifndef DISPLAY_H
#define DISPLAY_H

class Display
{
    std::vector <vector <char> > graph;
    public:
        Display(int a, int b);
        //friend void lay(Polynomial abc,Display cba);
        //void show();
};

#endif // DISPLAY_H

I was thinking that maybe vectors are doing problems. I tested it without vectors, but it didn't change anthing.

//Display.cpp
#include "Display.h"
#include <iostream>

using namespace std;


Display::Display(int a, int b)
{
    //ctor
    if(a%2==0)
        a++;
    if(b%2==0)
        b++;

    vector <char> help;
    vector <char> mid;

    for(int i=0; i<b; i++)
    {
        mid.push_back('-');
        if(i==(b+1)/2)
            help.push_back('|');
        else
            help.push_back(' ');
    }

    for(int i=0; i<a; i++)
    {
        if(i==(a+1)/2)
            graph.push_back(mid);
        else
            graph.push_back(help);
    }
}

Now it's Polynomial class it's working fine, but Display class no, and i don't know why.

//Polynomial.h
#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H
#include <vector>



//class Display;

class Polynomial
{...}


#endif // POLYNOMIAL_H


//Polynomial.cpp
#include "Polynomial.h"
#include <iostream>
#include <windows.h>
#include <cmath>

using namespace std;

// constructors and methods here
// everything here working fine

Aucun commentaire:

Enregistrer un commentaire