0
// Shop.h file --->

#pragma once

#include "Wholeseller.h"
#include <string>

class Shop
{
private:
    std::string name{};
    std::string rating{};
    int prise{};
    friend class Wholeseller;
};

/// Wholeseller.h file --->

#pragma once
#include "Shop.h"
#include <vector>

class Wholeseller
{
private:
    float rate;
    std::vector <Shop> abc{};

public:
    bool set_prise(int n);
};

/// main.cpp file --->

#include <iostream>
#include "Shop.h"
#include "Wholeseller.h"

using namespace std;

int main()
{
    Wholeseller ABC;

    return 0;
}

when I run main.cpp file I get this error

PS C:\Users\maddy\Desktop\code_practice.cpp\class_challange> cd "c:\Users\maddy\Desktop\code_practice.cpp\class_challange\experiment\" ; if ($?) { g++ main.cpp -o main } ; if ($?) { 
.\main }
In file included from Shop.h:3,
                 from main.cpp:2:
Wholeseller.h:9:18: error: 'Shop' was not declared in this scope
    9 |     std::vector <Shop> abc{};
      |                  ^~~~
Wholeseller.h:9:22: error: template argument 1 is invalid
    9 |     std::vector <Shop> abc{};
      |                      ^
Wholeseller.h:9:22: error: template argument 2 is invalid

I am not able to use Shop class in other files, however I have included it in header file. all the files are in same directory I have also made wholeseller friend of shop if I use wholeseller class in shop.h file, i didn't gate errors somehow...

  • Does this answer your question? [Circular includes in C++ - again](https://stackoverflow.com/questions/16404575/circular-includes-in-c-again) – Davis Herring Oct 11 '22 at 16:56

0 Answers0