I just learned about C++ classes in multiple files, but I cannot get the output I expect from it...
(main.cpp)
#include <iostream>
#include "Dog.h" //include to be able to use the class
using namespace std;
int main(){
Dog myDoggy();
cout << "here";
return 0;
}
(Dog.cpp)
#include "Dog.h" // includes the header file
#include <iostream>
using namespace std;
Dog::Dog(){ //class_it_belongs_to::function
cout << "Woof" << endl; //output I want to receive
}
(Dog.h)
// This is a C++ header file
#ifndef DOG_H
#define DOG_H
// You define everything here before you use it
class Dog{
public:
Dog();
};
#endif
// The reason for this file is because when you compile it, this will be showed to whoever wants to use this piece of code, whilst the other file will be turned into binary (so they cannot edit the bodies of the functions)
This is the output (I expect to see "woof (\n) here" but I only get "here": The output I get after using g++ to compile the code
I use Linux Mint 19.3 and g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0.