未定义对`Mosaic :: Mosaic()'的引用

Error in terminal of VS Code: /tmp/ccU4qzPn.o: In function main': azul.cpp:(.text+0xa7e): undefined reference toMosaic::Mosaic()'

azul.cpp :(。text + 0xa86):对`Mosaic :: printMosaic()'的未定义引用

collect2:错误:ld返回1退出状态*

azul.cpp

#include "Mosaic.h"
#include <iostream>

// int menuOption;
std::string playerOne;
std::string playerTwo;



void printMenu() {
    std::cout << "                             " << std::endl;
    std::cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" << std::endl;
    std::cout << "|                           |" << std::endl;
    std::cout << "|       Welcome to Azul     |" << std::endl;
    std::cout << "|                           |" << std::endl;
    std::cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" << std::endl;
    std::cout << "|        -----------        |" << std::endl;
    std::cout << "|         Main Menu         |" << std::endl;
    std::cout << "|        -----------        |" << std::endl;
    std::cout << "|        1. New Game        |" << std::endl;
    std::cout << "|        2. Load Game       |" << std::endl;
    std::cout << "|        3. Credits         |" << std::endl;
    std::cout << "|        4. Help            |" << std::endl;
    std::cout << "|        5. Quit            |" << std::endl;
    std::cout << "|                           |" << std::endl;
    std::cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" << std::endl;
    std::cout << "                             " << std::endl;
}

int main(void) {

    printMenu();

    std::cout << "Enter Your Choice: " << std::endl;

    char menuOption;
    std::cin >> menuOption;

    if (menuOption == '1') {
        std::cout << "\n\nStarting a new game..." << std::endl;

        std::cout << "\nEnter Name for Player One:" << std::endl;
        std::cin >> playerOne;

        std::cout << "\nEnter Name for Player Two:" << std::endl;
        std::cin >> playerTwo;

        std::cout << "\n\nLet's play!\n" << std::endl;
        std::cout << "-----------" << std::endl;
        std::cout << "Start Round" << std::endl;
        std::cout << "-----------" << std::endl;

        std::cout << "\nMosaic for " << playerOne << ":" << std::endl;

        Mosaic* mosaic = new Mosaic();
        mosaic->printMosaic();
    }

    return EXIT_SUCCESS;

};

马赛克

#include "Mosaic.h"
#include <iostream>



Mosaic::Mosaic(){

}
Mosaic::~Mosaic(){

}

void Mosaic::printMosaic() {

    for (int i = 1; i < 6; i++)
    {
        std::cout << i << ". ";
        for (int j = 6; j > i; j--)
        {
            std::cout << " ";
        }
        for (int j = 0; j < i; j++)
        {
            std::cout << ".";
        }
        std::cout << "|| . . . . ." << std::endl;
    }
}

马赛克

class Mosaic
{
    public:
        Mosaic();
        ~Mosaic();
        void printMosaic();
};

我认为问题出在指针上

Mosaic* mosaic = new Mosaic();
评论