mac 编译问题

时间:2021-04-15 06:42:28

标签: c++ gcc makefile

我正在 Windows 上开发一个项目。但是我复制了 c++h 文件并在 mac 上为它创建了一个 makefile。但是在编译时,我收到了这个消息。而且我不知道它来自哪里。

src/main.cpp:6:18: note: in instantiation of function template specialization 'std::__1::make_shared<WindowHandler, int, int>' requested here
        auto win = std::make_shared<WindowHandler>(900, 600);
                        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:3585:9: note: candidate constructor [with _A0 = int, _A1 = int] not viable: expects an l-value
      for 2nd argument
        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:3580:9: note: candidate constructor template not viable: requires 2 arguments, but 3 were
      provided
        __shared_ptr_emplace(_Alloc __a, _A0& __a0)
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:3590:9: note: candidate constructor template not viable: requires 4 arguments, but 3 were
      provided
        __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:3566:5: note: candidate constructor not viable: requires single argument '__a', but 3 arguments
      were provided
    __shared_ptr_emplace(_Alloc __a)
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:3559:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1
      argument, but 3 were provided
class __shared_ptr_emplace

这是生成文件

SRC     =   main.cpp            \
            Cells.cpp           \
            WindowHandler.cpp

OBJ     =   $(foreach source, $(SRC), src/$(source:.cpp=.o))
NAME    =   MazeGenerator
CFLAGS  =   -g -Wall -Wextra -std=c++17 -Isrc/include
LDFLAGS =   -lsfml-graphics -lsfml-audio -lsfml-window -lsfml-system
CC      =   g++
LD      =   g++

all: $(NAME)

$(NAME): $(OBJ)
    $(LD) -o $@ $^ $(LDFLAGS)

obj/%.o: src/%.cpp
    $(CC) -o $@ -c $^ $(CFLAGS)

clean:
    rm -rf $(OBJ)

fclean: clean
    rm -rf $(NAME)

re: fclean all

我尝试通过创建实例来替换我的智能指针并且它可以工作,但为什么它不能与智能指针一起使用。

这是我替换的地方

int main()
{
    //auto win = std::make_shared<WindowHandler>(900, 600);
    WindowHandler *win = new WindowHandler(900, 600);
    win->start();
    return 0;
}

并在标题中

class WindowHandler
{
public:
    WindowHandler(int, int);
    ~WindowHandler() {delete _cells;};
    void start();
    sf::RenderWindow& getWindow() { return *_window; };

private:
    sf::RenderWindow *_window;
    sf::Event event;
    //std::shared_ptr<Cell> _cells = std::make_shared<Cell>();
    Cell *_cells;
};

0 个答案:

没有答案