Original
As a basic test, I can define a class in my Main.cpp
and get the expected behavior from the constructor
#include <iostream>
class PrintConstructor
{
public:
PrintConstructor() {
std::cout << "Hello World!";
}
};
int main() {
PrintConstructor myResult;
return 0;
}
When compiling $ g++ -o Main Main.cpp
I get the printed "Hello World!" result.
However when placing my class into a separate .cpp
and .h
files I'm not getting anything printed.
Modularized
PrintConstructor.cpp
#include<iostream>
#include "PrintConstructor.h"
class PrintConstructor()
{
public:
PrintConstructor() {
std::cout << "Hello World!";
}
};
PrintConstructor.h
If I leave this blank, I don't get any errors, but I don't have the constructor printing like I'm expecting.
I have tried
class PrintConstructor
{
public:
PrintConstructor();
};
but I get an `undefined reference to PrintConstructor::PrintConstructor()'
When blank, I don't get an error, but I don't have the behavior from the constructor I'm expecting.
class PrintConstructor
{
};
Main
#include <iostream>
#include "LinkedList.h"
int main() {
PrintConstructor myResult;
return 0;
}