mercredi 8 septembre 2021

In function int main(): class name was not declared in this scope

Im using vscode and im new to c++. I learned how to create a header file link to its cpp and use it to main.cpp. The only problem bugs me out is why it causes an error this is my simple code.

Name.h

#include <iostream>
#include <string>
class myname
{
public:
    void setname(std::string name);
    void prname();
private:
    std::string Name;
};

Name.cpp

#include "Name.h"

void myname::setname(std::string name)
{
    Name = name;
}
void myname::prname()
{
    std::cout<<"Hello :"<<Name<<std::endl;
}

Maiin.cpp

#include <iostream>
#include <string>
#include "Name.h"
using std::cout;
using std::string;
using std::endl;

int main()
{
    myname Epoy;  // IN FUNCTION INT MAIN: ERROR myname was not declared in this scope 
    Epoy.setname("Jomar"); //note myname <-rename "BUT THIS IS NOT THE ERROR CAUSE THIS JUST HAPPEN BECAUSE OF THE ERROR ABOVE " 
    Epoy.prname();
    return 0;
}

also i tried so many method i even compiled this by using g++ Maiin.cpp Name.cpp - o Maiin Still didnt work

Aucun commentaire:

Enregistrer un commentaire