Using a class in ADT(abstract data types) or separate compilation in C++

  adt, c++, compilation, scope

I just started using separate compilation and ADT so I created a project to understand how to create the different types of files. I have created three files
main.cpp (main file)

#include "Interface.h" //include header file
#include <iostream>
#include <string>

using namespace std;

int main()
{
    hello();
    User user1;
}

Interface.cpp (implementation file where functions go)

#include "Interface.h"
#include <iostream>
#include <string>
using namespace std;
void hello()
{
 cout << "Hello" << endl;
}

Interface.h (header file where the class,defintions and data variables go)

#ifndef INTERFACE_H
#define INTERFACE_H
#include <string>

void hello();
class User
{
public:
    
    string name;
    int age;
};

#endif//INTERFACE_H


When I run the project it gives me the error:
Build: Debug in FirstProject (compiler: GNU GCC Compiler) ===|
C:UsersFirstProjectmain.cpp|14|error: ‘User’ was not declared in this scope|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 4 second(s))

and that’s referring to the main.cpp where I created user1.
Can someone please show how I declare the User class in the main function.
I have copied and pasted the code directly from my code. This is everything from my project I created called FirstProject.

Source: Windows Questions C++

LEAVE A COMMENT