小编sil*_*ent的帖子

帮助处理这些警告.[遗产]

我有一组代码,它模仿基本的图书馆编目系统.有一个名为items的基类,其中定义了通用id,title和year变量以及3个其他派生类(DVD,Book和CD).

基地[项目]

派生[DVD,书籍,CD].

程序运行,但我得到以下警告,我不知道如何解决这些问题.

>"C:\Program Files\gcc\bin/g++"  -Os -mconsole -g -Wall -Wshadow -fno-common mainA4.cpp -o mainA4.exe
In file included from mainA4.cpp:5:
a4.h: In constructor `DVD::DVD(int, std::string, int, std::string)':
a4.h:28: warning: `DVD::director' will be initialized after
a4.h:32: warning:   base `Items'
a4.h:32: warning:   when initialized here
a4.h: In constructor `Book::Book(int, std::string, int, std::string, int)':
a4.h:48: warning: `Book::numPages' will be initialized after
a4.h:52: warning:   base `Items'
a4.h:52: warning:   when initialized here
a4.h: In constructor `CD::CD(int, std::string, int, std::string, int)':
a4.h:66: warning: `CD::numSongs' will be …

c++ inheritance warnings class gcc-warning

5
推荐指数
2
解决办法
7937
查看次数

有关条件编译的快速问题(ifndef)

这可能是一个非常愚蠢的问题,但我需要确定.我在头文件中得到了一个类声明,例如.

#ifndef file_H
#define file_H

class ex{
private:

public:
};

#endif
Run Code Online (Sandbox Code Playgroud)

我已经被要求在相同的文件中编写方法定义,我已经完成了,我的问题是"#endif"是否保留在类声明之后的位置,还是在文件末尾之后.类方法定义?

c++ compiler-construction gcc include-guards header-files

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

将透明的.PNG图像模糊到屏幕上

嗨,我有一个图像,上面画着黑色矩形,背景是透明的.该文件保存为png(clear.png).然后我有另一个图像,它只是一个固定的红色背景,保存为jpeg(background.jpeg).我试图做的是使clear.png中的黑色矩形显示在纯红色背景图像的顶部.

这就是我所做的......

/*Transparent image*/
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <iostream>
using namespace std;
int main(int argc,char *argv[]){
    SDL_Surface *screen = NULL;
    SDL_Surface *background = NULL;
    SDL_Surface *transparentimage = NULL;

    if ( SDL_Init(SDL_INIT_EVERYTHING) == -1){
        cout <<"could not start sdl" << endl;
    }

    screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
    if ( screen == NULL){
        cout<<"could not create the screen" << endl;
    }

    background = IMG_Load("background.jpeg");
    if ( background == NULL){
        cout<<"could not load background" << endl;
    }

    transparentimage = IMG_Load("clear.png"); …
Run Code Online (Sandbox Code Playgroud)

c++ transparency gcc sdl background-image

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

帮助在Visual C++ Express中进行链接

我是VC++的新手,想知道如何在VC++中链接"wsock32.lib".我正在尝试编写一个简单的c ++服务器应用程序,这些是我得到的错误消息.那么我该如何在VC++中链接一些内容呢?wsock32也是我需要的正确的库吗?

1>------ Build started: Project: bla, Configuration: Debug Win32 ------
1>bla.obj : error LNK2019: unresolved external symbol _closesocket@4 referenced in function _main
1>bla.obj : error LNK2019: unresolved external symbol _send@16 referenced in function _main
1>bla.obj : error LNK2019: unresolved external symbol _recv@16 referenced in function _main
1>bla.obj : error LNK2019: unresolved external symbol _accept@12 referenced in function _main
1>bla.obj : error LNK2019: unresolved external symbol _listen@8 referenced in function _main
1>bla.obj : error LNK2019: unresolved external symbol _bind@12 referenced …
Run Code Online (Sandbox Code Playgroud)

c++ sockets visual-c++

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

在opencv中找到凸性缺陷?[根据给定的输入图像崩溃..]

我有一个计算图像凸包的程序。我正在尝试使用此信息来计算输入图像中存在的手指数量。从一些冲浪我发现这样做的方法(数手指)是通过

  1. 寻找轮廓
  2. 凸包
  3. 凸面缺陷

但是我在使用凸度缺陷函数时遇到了麻烦。它编译得很好,但在运行时程序会因某些输入图像而崩溃,但不会与其他图像一起崩溃,我似乎无法弄清楚原因。

这些是输入图像

  1. 此图像导致崩溃
  2. 但这个没有。
  3. 即使与上述类似,这也会导致崩溃

代码..

#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv/cxcore.h>
#include <stdio.h>

#define CVX_RED     CV_RGB(0xff,0x00,0x00)
#define CVX_GREEN   CV_RGB(0x00,0xff,0x00)
#define CVX_BLUE    CV_RGB(0x00,0x00,0xff)

int main(int argc, char* argv[]) {

  cvNamedWindow( "original", 1 );
  cvNamedWindow( "contours", 1 );
  cvNamedWindow( "hull", 1 );
  IplImage* original_img = NULL;

  original_img = cvLoadImage("img.jpg", CV_LOAD_IMAGE_GRAYSCALE );

  IplImage* img_edge = cvCreateImage( cvGetSize(original_img), 8, 1 );
  IplImage* contour_img = cvCreateImage( cvGetSize(original_img), 8, 3 );
  IplImage* hull_img = …
Run Code Online (Sandbox Code Playgroud)

c c++ opencv image-processing convex-hull

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

如何在C中将十六进制数读入unsigned int

我想将文本文件中的十六进制数读入无符号整数,以便我可以执行机器指令.它只是一个模拟类型的东西,它查看文本文件内部并根据值及其相应的指令输出寄存器中的新值.

例如,说明将是:

  • 1RXY - >将寄存器R保存为存储器地址XY中的值
  • 2RXY - >将寄存器R保存为XY值
  • BRXY - >跳转到寄存器R,如果xy是这个等等.
  • ARXY - > AND在内存地址XY处注册R值

文本文件在新行中包含类似的内容.(在十六进制中)

  • 120F
  • B007
  • 290B

我的问题是将每个单独的指令复制到无符号整数...我该怎么办?

#include <stdio.h>
int main(){
    FILE *f;
    unsigned int num[80];

    f=fopen("values.txt","r");
    if (f==NULL){
        printf("file doesnt exist?!");
    }

    int i=0;
    while (fscanf(f,"%x",num[i]) != EOF){
        fscanf(f,"%x",num[i]);
        i++;
    }
    fclose(f);
    printf("%x",num[0]);
}
Run Code Online (Sandbox Code Playgroud)

c file copying

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

确定服务器上已连接客户端的IP地址

我有一台服务器在一台机器上运行,并将其使用的端口转发到我的路由器,另一台运行客户端的机器使用ISP分配的外部IP地址而不是本地地址连接到服务器.这一切工作正常,它连接,但当我检查连接的套接字(客户端)的地址时,它显示的IP地址是完全不同的?它告诉我148.49.68.0.我在ipconfig上找不到这个,也不明白这是从哪里出来的.客户端不应该显示我的外部地址吗?(看到两台计算机使用相同的外部IP地址).

[编辑]添加了服务器源

#include <iostream>
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <string.h>
using namespace std;

int PORT;
const int winsock_version = 2;
const int max_con = 10;
string SERVER_ADDRS;

void Bind(SOCKET &serv,struct sockaddr_in &serv_info,int size);
void Listen(SOCKET &serv,int max_con);
void connection_info(struct sockaddr_in &client);
bool communication(SOCKET &client); 
SOCKET Accept(SOCKET &serv);

int main(void){

    WSADATA wsadata;
    if ( WSAStartup(MAKEWORD(winsock_version,0),&wsadata) == 0 ){
        cout<<"-[Initialized.]" << endl;
        cout<<"-[Server Address (leave blank to scan for all IP's)]: ";
        getline(cin,SERVER_ADDRS);
        cout<<"-[Port]: "; …
Run Code Online (Sandbox Code Playgroud)

c++ ip client-server winsock ip-address

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

覆盖文本文件中的特定行?

如何在c?中覆盖文本文件中的特定行?我在需要写入文件的多个变量中有值.

c variables file file-writing

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

析构函数和复制构造函数调用..(为什么在这些时候被调用)

我有以下代码

#include <iostream>
using namespace std;

class Object {

public:
   Object(int id){
     cout << "Construct(" << id << ")" << endl; 
     m_id = id;       
   }

   Object(const Object& obj){
      cout << "Copy-construct(" << obj.m_id << ")" << endl;  
      m_id = obj.m_id;
   }

   Object& operator=(const Object& obj){
      cout << m_id << " = " << obj.m_id << endl; 
      m_id = obj.m_id;
      return *this; 
   }

   ~Object(){
       cout << "Destruct(" << m_id << ")" << endl; 
   }
private:
   int m_id;

};

Object func(Object var) …
Run Code Online (Sandbox Code Playgroud)

c++ gcc destructor class copy-constructor

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

为什么这个微小的RSA实现会产生错误的结果?

我正在尝试实现一个简单的RSA加密/解密过程,我很确定我已经以正确的方式获得了方程式.虽然加密后似乎没有打印出正确的解密值.有任何想法吗?.

//test program
#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;
int gcd(int a, int b);

int main(){
    char character = 'A'; //character that is to be encrypted


    int p = 7;
    int q = 5;
    int e = 0; // just initializing to 0, assigning actual e value in the 1st for loop 


    int n = p*q;
    int phi = (p-1)*(q-1);
    int d = 0; // " " 2nd for loop

    //---------------------------finding 'e' with phi. where "1 < …
Run Code Online (Sandbox Code Playgroud)

c c++ encryption cryptography rsa

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