小编CB *_*ley的帖子

变量中的点?VC9在构建beecrypt时会出现解析错误

我想在VS2008下编译beecrypt库.但是以下几种结构会产生语法错误(C2059语法错误:'.'):

const hashFunction md5 = {
.name = "MD5",
.paramsize = sizeof(md5Param),
.blocksize = 64,
.digestsize = 16,
.reset = (hashFunctionReset) md5Reset,
.update = (hashFunctionUpdate) md5Update,
.digest = (hashFunctionDigest) md5Digest
};
Run Code Online (Sandbox Code Playgroud)

VC++不接受开头的点.如果我评论上面的内容,我稍后会收到链接错误(LNK2001未解析的符号_md5) - 所以我想它必须取消注释.

这个结构是什么?我需要什么?我如何告诉VS2008编译它?

c c++ c99 visual-studio

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

移植C++ - 从Windows到Unix的代码:systemcalls与函数名称冲突

我正在将一些狡猾的C++ Windows代码移植到Linux上,它在每个类中都使用了"open"和"close"的功能......非常糟糕的风格,还是?幸运的是,这不是Windows中的问题,因为他们的系统调用被命名为不同.

当我尝试调用systemcalls open()或close()时,我收到一些关于"没有匹配函数调用class:open()"的编译器错误.我不能在整个代码中重命名所有名为"class :: open"和"class :: close"的函数,我必须使用open()和close(),因为我正在使用串行端口.

所以我的问题是:我怎么能告诉编译器,我打开哪个?如何在C++中转义或隐藏类的命名空间?

c++ namespaces system-calls

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

有没有快速的方法来替换两个地图内容?

在我的代码中,我有一个地图,其中包含大量数据(~100MB)我需要将所有数据从一个地图复制到另一个地图.目前我用交换做这个,但根据我的理解,交换是一种花哨的方式来复制.有没有办法简单地转移两张地图使用的内存?我认为我可以用指针做到这一点,但我希望有一个更优雅的方式.

c++ swap

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

尝试调用虚拟析构函数时出现分段错误

尝试使用类型转换的指针调用析构函数时,我的代码出现分段错误。但是如果我将析构函数更改为非虚拟的,它就可以正常工作。

#include <iostream>
using namespace std;
class Test
{
public:
   Test() { cout << "Cons" << endl;}
   ~Test() {cout << "Des"<<endl;}
   void *var_ptr;
};
class Test3
{
public:
   Test3() { cout << "Cons3" << endl;}
   //virtual ~Test3(){cout << "Des3" << endl;};
   ~Test3(){cout << "Des3" << endl;};
};
class Test2:public Test3
{
public:
  Test2() { cout << "Cons2" << endl;}
 ~Test2() {cout << "Des2"<<endl;}
};
int  main ()
{
  Test *testPtr = new Test();
 int *ivalue ;
 ivalue = new int; …
Run Code Online (Sandbox Code Playgroud)

c++

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

返回字符串的C++函数不起作用,除非涉及到endl ......?

我在一个返回字符串的类中有一个函数.在这个函数中,我只能cout<<endl 在return语句之前添加函数时才能使它工作 .知道为什么会这样,或者我如何解决它?我在Mac上用Eclipse运行它

在"main.cpp"中:

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdlib>
#include "Braid.h"
using namespace std;

static int size=3;

int main(){  
Braid * b1 = new Braid(size);
b1->setCanon();//creates canonical braid. 

cout<<"a ";
cout<<b1->getName()<<endl;
cout<<" b ";
}  
Run Code Online (Sandbox Code Playgroud)

在"Braid.h"中:

  public:  
        Braid(int);  
        void setCanon();  
        string getName(); 
    };  
Run Code Online (Sandbox Code Playgroud)

在"Braid.cpp"中:

string Braid::getName(){  
    string sName="";  

    /* body commented out
    for(int i=0; i<height; i++)
    {
        for(int j=2; j<(width-2); j++)
            {
                sName += boxes[i][j];
                sName += "|";
            }
        }

        */  
        //cout<<endl;
        return sName; …
Run Code Online (Sandbox Code Playgroud)

c++ string stl

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

如何在没有#include <string>的情况下使用字符串?

在STL引用中给出了字符串类在字符串头中,然后不包括头如何运行以下程序而没有错误?

#include<iostream>

using namespace std;

int main() {
  string s;
  cin>>s;
  cout<<"string entered is : "<<s;
}
Run Code Online (Sandbox Code Playgroud)

我在ubuntu机器上使用g ++编译器.

c++

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

排序功能不适用于在堆栈上创建的功能对象?

#include<iostream>
#include<vector>
#include<algorithm>
class Integer
    {
public:
    int m;
    Integer(int a):m(a){};
    };
class CompareParts
    {
    public:
        bool operator()(const Integer & p1,const Integer & p2)
            {
            return p1.m<p2.m;
            }
    }obj1;
int main()
    {
    std::vector<Integer> vecInteger;
    vecInteger.push_back(Integer(12));
    vecInteger.push_back(Integer(13));
    vecInteger.push_back(Integer(5));
    vecInteger.push_back(Integer(7));
    vecInteger.push_back(Integer(9));
    Integer obj2();
    std::sort(vecInteger.begin(),vecInteger.end(),obj1);
    std::sort(vecInteger.begin(),vecInteger.end(),obj2);
    }
Run Code Online (Sandbox Code Playgroud)

为什么第二排序函数中的obj2会导致编译错误.

c++ sorting functor

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

我怎么能克服这个错误C2679:binary'>>':没有找到哪个运算符采用'const char []'类型的右手操作数

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <cstring>

void initialize(char[],int*);
void input(const char[] ,int&);
void print ( const char*,const  int);
void growOlder (const char [], int* );

bool comparePeople(const char* ,const int*,const char*,const int*);

int main(){

  char name1[25];
     char name2[25];
     int age1; 
  int age2;


 initialize (name1,&age1);
 initialize (name2,&age2);

 print(name1,age1);
 print(name2,age2);

 input(name1,age1);
 input(name2,age2);

 print(name1,age1);
 print(name2,age2);

 growOlder(name2,&age2);

 if(comparePeople(name1,&age1,name2,&age2))
    cout<<"Both People have the same  name and age "<<endl;
 return 0;
}

void input(const  char name[],int &age)
{
 cout<<"Enter a name :"; …
Run Code Online (Sandbox Code Playgroud)

c++

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

覆盖和超载

public class Module
{
    // required instance variables
    private String codeModule, titleModule;
    private int pointsModule;

    //three-argument constructor receiving a code, a title string, and a        
    //number of points, 
    //which sets the code, title and points data of the created object to    
    //the received values.
    public Module(String aCode, String aTitle, int aPoints)
    {
       codeModule = aCode;
       titleModule = aTitle;
       pointsModule = aPoints;
    }

    //set the instance data value codeModule to received argument newCode.
    public void setaCode(String newCode)      
    {
       codeModule = newCode; …
Run Code Online (Sandbox Code Playgroud)

java overriding overloading

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

c ++继承问题

我对此有疑问:

class A
{
  int a;
  int* pa;
public:
   A(int i):a(i) , pa(new int(a))
   {
      cout<<"A ctor"<<a<<endl;
   }
   ~A()
    {
      delete pa;
      cout<<"dtor\n";
    }
    int * &get()
    {
     return pa;
    }
};

class B : public A
{
     int b;
public:
      B (A obj): A(obj) , b(0)
      {
       cout<<"B ctor\n";
      }
      ~B()
      {
       cout<<"B dtor\n";
      }
};

int main()
{
 int i = 23 ; 
 A* p = new B(i);
}
Run Code Online (Sandbox Code Playgroud)

可以告诉我为什么最后一行main编译?我传递一个int进入B的构造,其预期的A目的,而不是.我相信它 …

c++ inheritance explicit-constructor rule-of-three

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

在没有放置新方法的情况下,将对象分配给c ++中的预定义地址

在c ++中是否可以在内存中的特定位置分配对象?我正在实现我的业余爱好os内核内存管理器,它提供void*了存储我的东西的地址,我想知道如何使用该指针在那里分配我的对象.我试过这个:

string* s = (string*)235987532//Whatever address is given.
*s = string("Hello from string\n\0");//My own string class
//This seems to call the strings destructor here even thought I am using methods from s after this in my code...
Run Code Online (Sandbox Code Playgroud)

唯一的问题是它调用字符串对象析构函数,它不应该这样做.任何帮助表示赞赏.

编辑:我不能使用placement new,因为我正在开发内核级别.

c++ pointers destructor placement-new

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