c++ outofline definition of XXXX 解决方法

 


   检查头文件与cpp文件的函数名称或参数是否相同。

  • 10
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
In A Tour of C++, Second Edition, Bjarne Stroustrup, the creator of C++, describes what constitutes modern C++. This concise, self-contained guide covers most major language features and the major standard-library components—not, of course, in great depth, but to a level that gives programmers a meaningful overview of the language, some key examples, and practical help in getting started. Stroustrup presents the C++ features in the context of the programming styles they support, such as object-oriented and generic programming. His tour is remarkably comprehensive. Coverage begins with the basics, then ranges widely through more advanced topics, including many that are new in C++17, such as move semantics, uniform initialization, lambda expressions, improved containers, random numbers, and concurrency. The tour even covers some extensions being made for C++20, such as concepts and modules, and ends with a discussion of the design and evolution of C++. This guide does not aim to teach you how to program (for that, see Stroustrup’s Programming: Principles and Practice Using C++, Second Edition), nor will it be the only resource you’ll need for C++ mastery (for that, see Stroustrup’s The C++ Programming Language, Fourth Edition, and recommended online sources). If, however, you are a C or C++ programmer wanting greater familiarity with the current C++ language, or a programmer versed in another language wishing to gain an accurate picture of the nature and benefits of modern C++, you can’t find a shorter or simpler introduction than this tour provides.
A Tour of C++ (2nd Edition) (C++ In-Depth Series) By 作者: Bjarne Stroustrup ISBN-10 书号: 0134997832 ISBN-13 书号: 9780134997834 Edition 版本: 2 出版日期: 2018-07-09 pages 页数: 815 In A Tour of C++, Second Edition, Bjarne Stroustrup, the creator of C++, describes what constitutes modern C++. This concise, self-contained guide covers most major language features and the major standard-library components—not, of course, in great depth, but to a level that gives programmers a meaningful overview of the language, some key examples, and practical help in getting started. Stroustrup presents the C++ features in the context of the programming styles they support, such as object-oriented and generic programming. His tour is remarkably comprehensive. Coverage begins with the basics, then ranges widely through more advanced topics, including many that are new in C++17, such as move semantics, uniform initialization, lambda expressions, improved containers, random numbers, and concurrency. The tour even covers some extensions being made for C++20, such as concepts and modules, and ends with a discussion of the design and evolution of C++. This guide does not aim to teach you how to program (for that, see Stroustrup’s Programming: Principles and Practice Using C++, Second Edition), nor will it be the only resource you’ll need for C++ mastery (for that, see Stroustrup’s The C++ Programming Language, Fourth Edition, and recommended online sources). If, however, you are a C or C++ programmer wanting greater familiarity with the current C++ language, or a programmer versed in another language wishing to gain an accurate picture of the nature and benefits of modern C++, you can’t find a shorter or simpler introduction than this tour provides.
### 回答1: qt out-of-line definition指的是在类的定义外部实现类成员函数的定义。在C++中,类的成员函数可以在类的定义内部实现,也可以在类的定义外部实现。当成员函数的实现在类的定义外部时,需要使用out-of-line definition。在Qt中,这种实现方式常用于大型类或者需要分离实现的类。 ### 回答2: qt out-of-line definition(qt的离线定义)是指在一个qt类中,某个方法或函数的实现被单独放在了一个cpp文件中而不是放在头文件中。这种做法有时被称为“Pimpl”(Pointer to Implementation, 引用类指针)。 这种做法的好处是可以隐藏类的内部实现,避免在头文件中暴露过多细节,也方便对代码进行更优秀的封装,降低代码的耦合度。 然而这样做需要在头文件中声明该函数,然后在cpp文件中进行实现。这就可能导致如果在多个cpp文件中都需要调用该方法时,可能会出现符号冲突,导致链接失败。为了解决这个问题,需要采用一些常用的方法,如在头文件中使用 inline,或者使用 extern 和 static 等方法来处理定义。 总之,qt out-of-line definition 是一种常用的代码实现方法,因其使用简便,方便封装,但需要注意符号冲突等问题。 ### 回答3: Qt中的out-of-line definition指的是在类定义的外部为该类中的成员函数提供实现的代码。在C++中,通常将一个类的声明和实现分为.h和.cpp两个文件,会将类的声明放在.h文件中,而将函数的实现放在.cpp文件中。这种分离的方式使得代码更易于维护和管理。 然而,在某些情况下,需要在类定义的外部为该类中的成员函数提供实现的代码,这就需要用到out-of-line definition。例如,当类的成员函数定义较为复杂,需要占用较多的代码行数时,将函数实现和声明分离可以使代码更可读,方便维护。另外,如果需要在不同的文件中使用该类的成员函数,也需要将函数的实现放在类的声明外部,这样才能避免出现函数重复定义的错误。 在Qt中,如果一个类的成员函数需要在类声明外部提供实现,需要将函数的声明放在class关键字后面,在成员函数定义时指定类名和作用域解析符::,然后再写出该函数的实现。例如: class MyClass { public: void myFunction(); // 函数声明 }; void MyClass::myFunction() { // 函数定义 // 函数实现代码 } 需要注意的是,在类定义的外部为成员函数提供实现时,要使用与类定义中的声明一致的访问修饰符。例如,如果在类定义中将成员函数声明为public,那么在类定义外部也需要将该函数实现定义为public。 总之,Qt中的out-of-line definition是对C++中类定义和实现分离的一种具体应用,能够提高代码的可读性和维护性,同时也能避免函数重复定义的错误。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值