标签: redefinition

C库 - 在C++中使用:重定义,不同的类型修饰符

我最近在纯C中构建了一个CSV库.头文件如下所示:

  #ifndef CSV_H
  #define CSV_H

    #include "unicode/ustdio.h"
    #include "unicode/uchar.h"
    #include "unicode/ucsdet.h"
    #include "unicode/ustring.h"

    #define T CSV_T
    typedef struct T *T;

    extern T    CSV_new(char *filename);
    extern void CSV_free(T *csv);
    extern int  CSV_length(T csv);
    extern void CSV_print_info(T csv);
    extern UChar **CSV_get_header(T csv);
    extern UChar ***CSV_get_values(T csv);
    extern long CSV_get_num_columns(T csv);
    extern long CSV_get_num_lines(T csv);
    extern char *CSV_get_charset(T csv);

    #undef T
    #endif
Run Code Online (Sandbox Code Playgroud)

struct CSV_T的实际定义在代码文件中完成,以隐藏实现.我经常在使用纯C的不同项目中使用该库,没问题.现在我想在使用C++构建的GUI应用程序中重用代码,并收到以下错误消息:

Error   C2373   'CSV_T': redefinition; different type modifiers     ... xxx\Projects\LibCSV\LibCSV\csv.h    10  
Run Code Online (Sandbox Code Playgroud)

C++是否处理了与C不同的typedef?混淆不清,......

c++ typedef redefinition

1
推荐指数
1
解决办法
364
查看次数

重新定义类类型 - c ++

我理解我的代码所遇到的问题,但尝试其他人建议的一些事情并不能解决我的错误.

这是我的错误消息:

In file included from proj07.driver.cpp:4:
proj07.string.cpp:10: error: redefinition of 'String::String()'
/user/cse232/Projects/project07.string.h:25: error: 'String::String()' previously defined here
proj07.string.cpp: In constructor 'String::String(const char*)':
proj07.string.cpp:19: error: expected primary-expression before 'char'
proj07.string.cpp:19: error: expected `;' before 'char'
make: *** [proj07.driver.o] Error 1
Run Code Online (Sandbox Code Playgroud)

这是我担心的那个:

proj07.string.cpp:10: error: redefinition of 'String::String()'
/user/cse232/Projects/project07.string.h:25: error: 'String::String()' previously defined here
Run Code Online (Sandbox Code Playgroud)

我知道我应该定义一次我的接口文件,但我不确定要改变什么,因为我尝试的一切都带来了更多的问题.

我的驱动程序(proj07.driver.cpp):

using namespace std;

#include <iostream>
#include "proj07.string.cpp"

int main()
{
  const char string1[] = {'a', 'b', 'c', 'd', 'e', 'f'};
  String test1();
  String test2(string1);
}
Run Code Online (Sandbox Code Playgroud)

我的支持文件(proj07.support.cpp): …

c++ class redefinition

0
推荐指数
1
解决办法
3413
查看次数

错误:先前在C++中定义的'int main(int,char**)'

我现在正在实现gtest,它给了我一个错误:主要在此定义.

这是utest.cpp

// Bring in my package's API, which is what I'm testing
#include "../src/test.cpp"
// Bring in gtest
#include <gtest/gtest.h>

// Declare a test
TEST(TestSuite, testCase1)
{
     EXPECT_EQ(5,getX(5));
}

// Run all the tests that were declared with TEST()
int main(int argc, char **argv){
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
Run Code Online (Sandbox Code Playgroud)

这是我正在测试test.cpp的代码

#include "ros/ros.h"
#include "std_msgs/String.h"
#include <Project2Sample/R_ID.h>
#include <geometry_msgs/Twist.h>
#include <nav_msgs/Odometry.h>
#include <sensor_msgs/LaserScan.h>


#include <sstream>
#include "math.h"

int getX(int x)
{
    return x;
}

int main(int argc, char **argv)
{ …
Run Code Online (Sandbox Code Playgroud)

c++ program-entry-point compiler-errors googletest redefinition

0
推荐指数
1
解决办法
6256
查看次数

C++中的重新定义,头文件中的先前定义?

所以我很困惑.尝试实现先前在头文件中声明的方法时,我收到重新定义错误.我在标题中添加了包含防护,但仍然遇到了同样的错误.如果有人能向我解释我没有看到的东西,那就太棒了.

在main.cpp包含的文件中:2:./ something.cpp:7:12:错误:重新定义'method'int Thing :: method(void)^ ./ thing.hpp:12:6:注意:之前的定义在这里int方法(void){}; ^

- 编辑 -

我现在得到以下内容:

重复符号__ZN5Thing6methodEv in:main.o thing.o ld:1个用于体系结构x86_64的重复符号

thing.hpp:

#ifndef THING_H
#define THING_H

class Thing {

public:
        int a;
        int b;
        char c;

        int method(void) {};
        Thing(int anA, int aB, char aC): a(anA), b(aB), c(aC) {};


};

#endif
Run Code Online (Sandbox Code Playgroud)

thing.cpp

#include <iostream>
#include <stdio.h>
#include "thing.hpp"

using namespace std;

int Thing::method(void)
{
        return 5;

}
Run Code Online (Sandbox Code Playgroud)

main.cpp中

#include <iostream>
#include "thing.cpp"

using namespace std;

Thing* thing = new Thing(5,5,'c');

int main(int argc, char …
Run Code Online (Sandbox Code Playgroud)

c++ header include guard redefinition

0
推荐指数
1
解决办法
3838
查看次数

遵循一个定义规则,但 C++ 抛出重新定义错误

C++ 中非常奇怪的重定义错误,特别是因为包括 main 在内的所有其他文件都没有错误。

我有我的标题(各种动物)和一个实现文件“animals.cpp”。

我的标题遵循以下格式:

class Mammal : public Animal{
    public:
        Mammal(){} //empty constructor
        virtual ~Mammal(){} // destructor
        void createNewMammalObject(std::string name, std::string trackingNum, std::string nurse, std::string subType, std::string type){}
        std::string getSubtype() {}
        void setSubtype(std::string subType){}
        int getNursing(){}
        void setNursing(int nursing){}
        void setType(std::string type){}
        int getNumEggs(){}

    protected:
        int nursing;
};
Run Code Online (Sandbox Code Playgroud)

实现文件中的实现如下所示:

Mammal::Mammal() {} //empty constructor

virtual Mammal::~Mammal(){} // destructor

void Mammal::createNewMammalObject(std::string name, std::string code,std::string nurse,std::string subType, std::string type){
    this->setNursing(nursing);
    this->setSubType(subType);
    this->createNewAnimalObject(name, trackingNum,subType,type);
}

std::string Mammal::getSubtype() {
    return subType;
}

void …
Run Code Online (Sandbox Code Playgroud)

c++ redefinition c++11

-1
推荐指数
1
解决办法
45
查看次数

为什么我总是收到形式参数重新定义错误

#include <iostream>
using namespace std;
void  mf_option(int player1, int player2);
void  mf_option2(int player1, int player2);
void  mf_option3(int player1, int player2);


int main()
{
    int player1, player2;
    cout << "\n\n\nWlcome to \"Rock Paper Scissor game\"\n";

    cout << " Type 0 for rock, 1 for paper , and 2 for scissors\n";
    cout << "Player 1, choose 0, 1 or 2: ";
    cin >> player1;
    system("clear");
    cout << " Type 0 for rock, 1 for paper , and 2 for scissors\n";
    cout << …
Run Code Online (Sandbox Code Playgroud)

c++ user-defined-functions redefinition

-2
推荐指数
1
解决办法
1万
查看次数