在C ++中调试非链接头文件

时间:2016-11-03 21:00:03

标签: c++ debugging header-files linker-errors

只是想知道是否有人知道如何解决这个问题。

非常感谢!!

在main.cpp中使用此代码:

//
//  main.cpp
//  Chess
//
//  Created by Akshar Ramkumar on 9/29/16.
//  Copyright © 2016 Akshar Ramkumar. All rights reserved.
//

#include <iostream>
#include "DataStructures.hpp"


int main() {
    struct Piece {
        int Type;
        int x;
        int y;
        bool Captured;
        bool Color;
        char pictfile[7];
    };



    struct Piece All[32];
    setup(All);
    return 0;
}

这个代码在DataStructures.hpp中:

#ifndef DataStructures_hpp
#define DataStructures_hpp
void setup(struct Piece All[32]);


#endif

这个代码在DataStructures.cpp中:

//
//  Classes.cpp
//  Chess
//
//  Created by Akshar Ramkumar on 10/13/16.
//  Copyright © 2016 Akshar Ramkumar. All rights reserved.
//Pawn = 0
//Rook = 1
//Knight = 2
//Bishop = 3
//King = 4
//Queen = 5

struct Piece {
    int Type;
    int x;
    int y;
    bool Captured;
    bool Color;
    char pictfile[7];
};

void setup(struct Piece All[32]){

    int TypeArray[32]={0,0,0,0,0,0,0,0,1,1,2,2,3,3,4,5,0,0,0,0,0,0,0,0,1,1,2,2,3,3,4,5};
    int xValues[32]={0,1,2,3,4,5,6,7,0,7,1,6,2,5,3,4,0,1,2,3,4,5,6,7,0,7,1,6,2,5,3,4};
    int yValues[32]={1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7};


    for (int i=0;i<32;i++){
        All[i].Type = TypeArray[i];
        All[i].y = yValues[i];
        All[i].x = xValues[i];
        All[i].Color = true;
        All[i].Captured = false;


        if (i>15){
            All[i].Color = false;
        }


    }
}

我收到一条错误消息:在main.cpp中调用“Setup”没有匹配功能。任何想法

1 个答案:

答案 0 :(得分:1)

代码的基本框架:

//
//  main.cpp
//  Chess
//
//  Created by Akshar Ramkumar on 9/29/16.
//  Copyright © 2016 Akshar Ramkumar. All rights reserved.
//

#include <iostream>
namespace DataStructures {
    struct Piece {
        int Type;
        int x;
        int y;
        bool Captured;
        bool Color;
        char pictfile[7];
    };

     void setup(Piece* pieces) {
          //TODO
     }
};

int main() {

    DataStructures::Piece All[32];
// Initialize All[32] here
    DataStructures::setup(All);
    return 0;
 }