标签: header-files

从.h文件中删除已编译的方法及其后果

我有一个一直存在的二进制文件.它有一个C级,它一直存在.我们必须向C类引入一个新的方法M,但我们只希望一些用户知道这种方法M的存在.

通过从.h文件中删除这样的方法,我们可以介绍哪个问题?这种方法是否会向后兼容?

编辑:我们实际上并不关心是否有办法找到方法.我们只想确保只有人知道他们在做什么,才能使用它.

c++ header-files

0
推荐指数
2
解决办法
100
查看次数

C++:包括头文件失败编译但包括源cpp文件编译

这可能非常简单,但它在我走下c ++路的过程中阻碍了我.我目前正在通过加速c ++阅读,我决定过度使用其中一个练习.这一切都运行良好,我的代码运行良好,直到我将它分成一个标题和单独的源文件.当我导入包含我写的一些函数的.cpp源文件时,一切运行正常.但是,当我尝试通过头文件导入函数时,它失败可怕,我得到以下错误.我正在使用Geany的gcc进行编译,直到现在它都运行良好.谢谢你的帮助.

错误:

g++ -Wall -o "quartile" "quartile.cpp" (in directory: /home/charles/Temp)
Compilation failed.
/tmp/ccJrQoI9.o: In function `main':
quartile.cpp:(.text+0xfd): undefined reference to `quartile(std::vector<double, std::allocator<double> >)'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

"stats.h":

#ifndef GUARD_stats_h
#define GUARD_stats_h

#include <vector>

std::vector<double> quartile(std::vector<double>);

#endif
Run Code Online (Sandbox Code Playgroud)

"stats.cpp":

#include <vector>
#include <algorithm>
#include "stats.h"

using std::vector;    using std::sort;

double median(vector<double> vec){
     //code...
}

vector<double> quartile(vector<double> vec){
     //code and I also reference median from here.
}
Run Code Online (Sandbox Code Playgroud)

"quartile.cpp":

#include <iostream>
#include <vector>
#include "stats.h" //if I change this …
Run Code Online (Sandbox Code Playgroud)

c++ gcc header-files

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

头文件中的struct无法识别

practice.h

struct CandyBar
{
    string name;
    double weight;
    int calories;

};
Run Code Online (Sandbox Code Playgroud)

practice.cpp

#include    <iostream>
#include    <string>
#include    "practice.h"  

using namespace std;

int main()
{
    CandyBar snacks{ "Mocha Munch", 2.3, 350 };

    cout << snacks.name << "\t" << snacks.weight << "\t" << snacks.calories << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我构建解决方案时,我得到错误:

practice.h(5): error C2146: syntax error : missing ';' before identifier 'name'

practice.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

error C2440: 'initializing' : cannot convert …
Run Code Online (Sandbox Code Playgroud)

c++ struct header-files

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

未解决的符号错误

我正在使用Visual Studio 2012进行编程原理和实践练习.当尝试编译下面的源代码时,我收到链接器错误:

未解决的符号int foo.

我不明白为什么这个符号没有得到解决.

my.h

extern int foo;
void print_foo();
void print(int);
Run Code Online (Sandbox Code Playgroud)

my.cpp

#include "my.h"
#include "../../std_lib_facilities.h"

void print_foo()
{
    cout<<foo<<'\n';
}

void print(int i)
{
    cout<<i<<'\n';
}
Run Code Online (Sandbox Code Playgroud)

use.cpp

#include "my.h"

int main(){
    int foo = 7;

    print_foo();
    print(99);
}
Run Code Online (Sandbox Code Playgroud)

c++ header-files unresolved-external extern compilationunit

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

C++头文件/实现文件和重载操作符

我经常使用C++并且遇到一个让我失望的简单错误.

在Xcode中,我有以下两个错误:在Event.h中:Control reaches end of non-void function 在Event.cpp中:Overloaded operator must have at least one argument of class or enumeration

这两个错误都在方法签名的行上

bool operator () (Event *left, Event *right)
Run Code Online (Sandbox Code Playgroud)

这里是完整的.h和.cpp文件(还没有那么多):Event.h

#ifndef __EventSimulation__EventComparison__
#define __EventSimulation__EventComparison__

#include <iostream>
#include "Event.h"
class EventComparison {
public:
    bool operator () (Event *left, Event *right){}

};
#endif
Run Code Online (Sandbox Code Playgroud)

Event.cpp

#include "EventComparison.h"
#include "Event.h"

bool operator() (Event *left, Event *right) {
    return left->time > right->time;
}
Run Code Online (Sandbox Code Playgroud)

有人可以帮我修复这个错误并解释什么/为什么发出编译错误以及如何在功能中避免这种情况.谢谢你的帮助!

c++ operator-overloading header-files

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

导航/ usr/include/files时使用Vim查找定义

我发现当你想在linux下做一些事情时,在头文件之间导航是偶然的.例如,当我想找到某个东西的定义时struct sockaddr_storage.我现在正在做的是:!find /usr/include/ -type f | xargs grep " struct sockaddr ".它很强大,但对我来说并不令人信服.

是否有更简单的方法来浏览.h文件,如其他IDE,例如VStudio,提供?(几乎是C/CPP用户)ctags和cscope或tagbar是供项目使用的,在这种情况下它们能让我受益吗?

c vim header-files

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

c ++中的iostream,stdio.h和conio.h头文件有什么区别?

我在所有这三个头文件之间感到困惑.我在Balagurusamy for C++中读到它,所有这些文件都用于输入和输出.但有什么区别.我知道我们使用stdio.h用于scanf和printf而我们使用iostream for cin和cout.But有什么用途

c++ header-files

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

在将.obj转换为.h时不能使用'defined(@array)'警告

我正在尝试将我的.obj文件转换为.h头文件,但我得到"无法使用"定义(@array)'(也许你应该省略已定义的()?)"警告而不是.h文件已创建.

我试着更换@center到$center或omintting defined()但它创建的.exe文件!
我在某处读到它可能是一个perl版本问题,我的是5.22,我找不到更高版本的尝试.

Update1:
我把"obj2opengl.pl"和"myobject.obj"放在同一个文件夹中.并尝试在控制台(win10)中使用此代码转换它: c:\obj2openglfolder>obj2opengl.pl myobject.obj

Update2:
这是导致问题的line154代码:

if(defined(@center)) {
    $xcen = $center[0];
    $ycen = $center[1];
    $zcen = $center[2];
}
Run Code Online (Sandbox Code Playgroud)

Update3:
这是整个代码:

# -----------------------------------------------------------------

# Main Program

# -----------------------------------------------------------------

handleArguments();
# derive center coords and scale factor if neither provided nor disabled

unless(defined($scalefac) && defined($xcen)) {
calcSizeAndCenter();

}


if($verbose) {
printInputAndOptions();

}


# TODO check integrity: Does every referenced vertex, normal and coord 
exist?

loadData();

normalizeNormals();


if($verbose) {
printStatistics();

}


writeOutput();


# ----------------------------------------------------------------- …
Run Code Online (Sandbox Code Playgroud)

opengl perl header-files .obj

0
推荐指数
2
解决办法
5121
查看次数

什么是"阶级的例子"; 在头文件中意味着什么?

我有一个关于真正让我困惑的事情的问题!

我们在这里看一下这段代码:

#ifndef HEADER_H
#define HEADER_H
#include <iostream>

class example;
class anything_else;

class A {
      public:
           A();
};

...
Run Code Online (Sandbox Code Playgroud)

是什么class example;和class anything_else;意味着,虽然class A {};被宣布?在CPP文件中,我看到了诸如此类的定义void example::release() { ... }......

我真的很困惑,有没有人有class example;...... 的例子?

问候!

c++ oop syntax class header-files

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

有没有一种方法可以声明一个不包含&lt;complex.h&gt;的复数?

我想使用该<complex.h>库来加速某些计算,其中可能包括多达20个复杂元素和运算(+-* /)。但是,我的同事声明了一个结构:

struct complex {
    double a;
    double b;
};
Run Code Online (Sandbox Code Playgroud)

因此,complex由于与上述结构冲突,无法使用来自库的宏。

事实是,由于对当前项目的巨大影响,我无法更改结构的名称。我尝试使用_Complex宏来代替,并取出#include <complex.h>头,它的工作,但_Imaginary_I,_Complex_I还是I不起作用。

#include <stdio.h>      /* Standard Library of Input and Output */
// #include <complex.h>    /* I want to remove this */    

int main() {
    struct complex
    {
        double a;
        double b;
    };
    double _Complex z1 = 1.0;// + 3.0 * _Complex_I;
    double _Complex z2 = 1.0;// - 4.0 * _Complex_I;    

    // none of these …
Run Code Online (Sandbox Code Playgroud)

c c99 standard-library header-files complex-numbers

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