我已成功将一个动态库添加到程序中,但是当我尝试将头文件包含在项目的第二个文件中时,我会收到有关类重新声明的错误.如果这还不够,我会添加更多信息
你能帮我解决下面的错误:
致命错误C1083:无法打开包含文件:'graphics.h':没有这样的文件或目录
#include<dos.h>
#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
union REGS in,o;
circ()
{
int i;
for(i=0;i<15;i++)
circle(320,240,i*10);
rectangle(240,160,400,320);
}
bulb()
{
int i=1,c=1;
randomize();
while(!kbhit())
{
if((i%2)==0)
setcolor(c++);
setfillstyle(1,getcolor());
circle(320,240,i*20);
putpixel(320-i+2,240-i+2,1);
floodfill(320-i+2,240-i+2,getcolor());
delay(1000);
i++;
if(i>=5)
i=1;
}
}
dot()
{
int i,j,of=40,wid=5;
setcolor(8);
setfillstyle(1,getcolor());
for(i=of;i<getmaxx();i+=of)
bar(i,0,i+wid,getmaxy());
for(i=of;i<getmaxy();i+=of)
bar(0,i,getmaxx(),i+wid);
for(i=of;i<getmaxx();i+=of)
for(j=of;j<getmaxy();j+=of)
{
setcolor(15);
setfillstyle(1,getcolor());
circle(i+2,j+2,4);
floodfill(i+2,j+2,getcolor());
}
}
void main()
{
int x=0,y=10,gd=DETECT,gm,i;
initgraph(&gd,&gm,"c:\tc\bgi");
setcolor(YELLOW);
settextstyle(1,0,6);
outtextxy(0,240,"Count the black dots.....");
sleep(4);
cleardevice();
dot();
getch();
cleardevice();
setcolor(YELLOW);
settextstyle(1,0,4);
outtextxy(0,240,"I bet the lines of …Run Code Online (Sandbox Code Playgroud) 我有一个有阵列的结构.
struct Page_Directory {
public:
int numEntries;
int nextDirPage;
int [] array;
};
Run Code Online (Sandbox Code Playgroud)
但是,我总是希望这个数组具有一定的长度,因此这个结构的大小总是4 + 4 + 100*4字节.
我不希望有如下结构声明:
struct Page_Directory {
public:
int numEntries;
int nextDirPage;
int *array;
};
Run Code Online (Sandbox Code Playgroud)
因为这个结构的大小是4 + 4 + 4 = 12个字节(即使我通过使用new或分配内存到条目malloc).
现在,我该如何实现这一目标?我不能把头文件中的第一个声明放在头文件中,你不要在头文件中放入数组大小的细节,只是每个成员的类型.
我想在我的javaScript中使用.h文件中的定义:
我从用户HTML文件输入,并希望在html文件中显示它们,如:
input = 5
Run Code Online (Sandbox Code Playgroud)
.h文件包含define:
#define CODE 5
Run Code Online (Sandbox Code Playgroud)
我想向用户输出:CODE
谢谢 !
我正在为我的结构课开展一个小项目,并且遇到一个问题,即使TA无法弄清楚.有人建议我在这里发帖,我可能会得到一些帮助.所以这里:
概述: 我正在使用g ++编译包含许多头(.h)文件及其相应实现(.cpp)文件的项目.该项目涉及3个独立的结构,并在它们之间进行时序比较.正在实现和比较的结构是二进制最小堆,左侧堆和倾斜堆.最小堆实现已完成,编译正常.但是现在我正在转向其他结构,我正在遇到我认为(我知道)编译器错误.
问题 我正在充实左派堆的存根文件,并且就编译器而言已经遇到了问题.特别是我收到的错误是:
leftHeap.cpp:15:1: error: ‘LeftistHeap’ does not name a type
Run Code Online (Sandbox Code Playgroud)
代码 这里是相关代码:
leftHeap.h
#ifdef LEFTHEAP_H
#define LEFTHEAP_H
class LeftistHeap{
public:
int *root;
LeftistHeap();
~LeftistHeap();
};
#endif
Run Code Online (Sandbox Code Playgroud)
leftHeap.cpp
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <stdio.h>
#include <math.h>
#include "leftHeap.h"
using namespace std;
//Constuctor
LeftistHeap::LeftistHeap(){
root = NULL;
}
Run Code Online (Sandbox Code Playgroud)
包含leftHeap.h的唯一其他地方是main.cpp
main.cpp中
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <stdio.h>
#include <math.h>
#include "minHeap.h"
#include "leftHeap.h"
#include "skewHeap.h"
using namespace std;
int main(){
...
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的makefile:
生成文件
all: lab10 …Run Code Online (Sandbox Code Playgroud) 我在C中找不到我的代码有什么问题:
error.h
#ifndef ERROR_H_INCLUDED
#define ERROR_H_INCLUDED
void myfunc(bool**,int); //error line 1
#endif
Run Code Online (Sandbox Code Playgroud)
这是函数声明:
error.c
#include "error.h"
void myfunc(bool **rel,int num){ //error line 2
//function code here
}
Run Code Online (Sandbox Code Playgroud)
该函数的调用是:
main.c中
#include "error.h"
int main(){
bool **rel;
int num;
myfunc(rel,num);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码返回错误
预期')'在'*'之前
在错误行1和错误行2.我把功能代码放在注释中,我仍然有这个错误.我知道,这种错误是一个缺失; 或者)在大多数时间,但我花了几个小时,但没有发现错误.
通常,我通常会在头文件中包含依赖项,以便在将该头添加到源文件时,无需挖掘其他所需的头即可进行编译。
但是,在回顾了一些其他编码标准之后,似乎经常禁止这样做,因为头文件将不包含任何#include语句。
我真的对此没有任何讨论-禁止这种做法的原因是什么,或者纯粹是出于偏爱?
-
例如,typedef.h包含U8的typedef。my_header.h声明void display_message(U8 arg);
应该将对typedef.h的引用放入my_source_file.c或my_header.h?
所以,我正在尝试用C创建这个二进制树程序,它只是不断抛出最糟糕的编译错误.每当我更改某些内容以找到导致错误的内容时,它就会发生变化!我没有忘记我的包含守卫,我曾经使用过#pragma.如果我将结构放在标题中,我会得到不兼容的类型,如果我把它放在.c中,我会重新定义pretty_print,当我重命名pretty_print时,它会消失.当我修剪bintree.c中的其他函数和标题时,错误更改为intTree未定义.如果我然后将intTree更改为int,则它变为不兼容的类型.如果我将标头合并到.c中,这就消失了.现在它已经消失了.我认为这些可能是单独的错误,而且变化的错误可能是我的坏事,但它正在发生,我不知道为什么.我将展示代码,演示尽可能多的这些,但每当我尝试复制我所做的时,它会抛出不同的错误.但我并不沮丧.我希望能够发布一个格式正确的问题和有用的信息,但我没有,尽管在这个程序上花了几个小时.
bintree.cxx
#include "bintree.h"
int add(intTree* root,int key,void* val){
if(!root){
root=malloc(sizeof(intTree));
if(!root){
return 1;
}
root->key=key;
root->val=val;
root->left=0;
root->right=0;
return 0;
}
if(key>root->key){
if(root->right){
return add(root->right,key,val);
}else{
root->right=(intTree*) malloc(sizeof(intTree));
if(!root->right){
return 1;
}
root->right->key=key;
root->right->val=val;
root->right->left=0;
root->right->right=0;
return 0;
}
}
if(key<root->key){
if(root->left){
return add(root->left,key,val);
}else{
root->left=malloc(sizeof(intTree));
if(!root->left){
return 1;
}
root->left->key=key;
root->left->val=val;
root->left->left=0;
root->left->right=0;
return 0;
}
}
return 2;
}
void* get(intTree* root,int key){
if(!root){
return 0;
}
if(key>root->key){
return get(root->right,key);
}
if(key<root->key){
return get(root->left,key);
}
return root->val; …Run Code Online (Sandbox Code Playgroud) 将头文件中的变量声明为指针或非指针之间有什么区别?我不确定我是否正确理解这些差异.
例如
class MyClass {
private:
MyOtherClass* moc; // pointer
MyOtherClass moc2; // no pointer
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,在将变量声明为指针时,我已经提出了以下优点/缺点.
好处:
缺点:
还有什么可说的?
是否有任何选项在头文件中使用std而不使用任何#include语句?我在头文件中有一个类如下;
class Sequence{
private:
std::string sequence;
unsigned length;
public:
/* Constructors */
Sequence (void);
Sequence (std::string, unsigned);
Sequence (const Sequence &);
/* Destructor Definition */
~Sequence(){}
/* Overloaded Assignment */
Sequence & operator
= (const Sequence &seq)
{
sequence = seq.sequence;
length = seq.length;
return *this;
}
/* Setter and Getter Functions */
void setSequence(std::string);
void setLength(unsigned);
std::string getSequence(void);
int getLength(void);
};
Run Code Online (Sandbox Code Playgroud)
如果不包含iostream,则无法正确编译.但是,我在相关问题中阅读了一些注释,其中我们不应在头文件中包含库和另一个头文件.所以?
header-files ×10
c++ ×6
c ×5
binary-tree ×1
declaration ×1
function ×1
g++ ×1
include ×1
iostream ×1
javascript ×1
makefile ×1
pointers ×1
prototype ×1
std ×1
struct ×1
variables ×1
visual-c++ ×1
winapi ×1
windows ×1