小编Jon*_*ely的帖子

用G ++增强静态链接问题

我有一个应用程序,动态链接都可以,但是当我尝试使用静态链接进行编译时,我有以下错误.

我的应用程序使用boost线程,asio

错误:

/tmp/ccMj2fHI.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x237): undefined reference to `boost::system::get_system_category()'
test.cpp:(.text+0x243): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x24f): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x25b): undefined reference to `boost::system::get_generic_category()'
test.cpp:(.text+0x267): undefined reference to `boost::system::get_system_category()'
/tmp/ccnCWj1O.o: In function `__static_initialization_and_destruction_0(int, int)':
AccountSe.cpp:(.text+0x507): undefined reference to `boost::system::get_system_category()'
AccountSe.cpp:(.text+0x513): undefined reference to `boost::system::get_generic_category()'
AccountSe.cpp:(.text+0x51f): undefined reference to `boost::system::get_generic_category()'
AccountSe.cpp:(.text+0x52b): undefined reference to `boost::system::get_generic_category()'
AccountSe.cpp:(.text+0x537): undefined reference to `boost::system::get_system_category()'
Run Code Online (Sandbox Code Playgroud)

所有源文件都有类似的错误.

编译命令行:

g ++ -L/usr/lib/-lboost_system -lboost_thread -o newserver -static /usr/lib/libboost_thread.a /usr/lib/libboost_system.a stdafx.cpp test.cpp AccountSe.cpp ... -lpthread -std …

c++ boost g++ undefined-reference static-linking

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

我误解了c ++纯虚函数和接口的东西

我喜欢在几个类中定义良好的接口,为此我在每个类需要实现的抽象类中创建了纯虚函数.
但我面临的问题是我可以实例化类,所以我必须创建另一个继承接口类的类,所有其他类都需要从这个基类继承.以下是代码示例:

界面

class Interface
{
     virtual std::string getName() = 0;
}

class Base : public Interface
{
   virtual std::string getName(return std::string("Base") ;)
}

class A : public Base
{
  std::string getName(return std::string("A") ;)

}

class B : public Base
{
  std::string getName(return std::string("B") ;)

}
Run Code Online (Sandbox Code Playgroud)

所有这些所以我可以在代码中为A和B提供相同的类型.
我可以只使用Interface没有Base类的类吗?
像这样的东西:

class A : public Interface
{
  std::string getName(return std::string("A") ;)

}
Run Code Online (Sandbox Code Playgroud)

c++ inheritance pure-virtual

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

重载operator <<输出bool值.为什么?

xml_attribute.h

#pragma once
#ifndef XML_ATTRIBUTET_H
#define XML_ATTRIBUTET_H

#include <string>
#include <iostream>

struct XML_AttributeT{

    std::string tag;
    std::string value;

    //constructors
    explicit XML_AttributeT(std::string const& tag, std::string const& value);
    explicit XML_AttributeT(void);

    //overloaded extraction operator
    friend std::ostream& operator << (std::ostream &out, XML_AttributeT const& attribute);
};
#endif
Run Code Online (Sandbox Code Playgroud)

xml_attribute.cpp

#include "xml_attribute.h"

//Constructors
XML_AttributeT::XML_AttributeT(std::string const& tag_, std::string const& value_)
: tag{tag_}
, value{value_}
{}
XML_AttributeT::XML_AttributeT(void){}

//overloaded extraction operator
std::ostream& operator << (std::ostream &out, XML_AttributeT const attribute){
    return out << attribute.tag << "=" << attribute.value;
}
Run Code Online (Sandbox Code Playgroud)

driver.cpp

#include <iostream> …
Run Code Online (Sandbox Code Playgroud)

c++ reference operator-overloading most-vexing-parse c++11

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

我使用输入/输出流库吗?

如果您喜欢C++编程中的那种方式,我会尝试使用,std::因为有人告诉我这是一个好习惯,而不是using namespace std;因为它污染了全局命名空间,所以我是新手或菜鸟.我不确定为什么std::cin >> name;从下面的代码中产生错误,no operator '>>' matches these operands下面是完整的源代码.

#include "stdafx.h"
#include <ios>
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
{
    int x, y;
    std::string name;

    std::cin >> name;
    std::cin >> x;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ iostream

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

Groovy比较两个列表以查找具有共同元素的列表

如何在groovy中比较两个列表

[N1OB] == [ABCD9, ABCD8, ABCD7] -> should return false

[ABCD1, ABCD1, ABCD1, ABCD1] == [ABCD9, ABCD8, ABCD7] -> should return false

[ABCD1, ABCD1, ABCD1, ABCD1] == [ABCD9, ABCD8, ABCD1] -> should return true
Run Code Online (Sandbox Code Playgroud)

那里有任何常规功能吗?

提前致谢

groovy compare

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

无法在C++代码中调试字符串转换事物

我是C++ OOP概念的新手.我目前在getter和setter函数中使用字符串声明的问题.我使用eclipse IDE,我得到的错误是

error: cannot convert 'Student::getname' from type 'std::__cxx11::string (Student::)() {aka std::__cxx11::basic_string<char> (Student::)()}' to type 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}'
return getname;

代码如下:

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

class Student
{
private:
    int rollno;
    string name;
    string school;
public:

void setrollno(int i)
{
    rollno =i;
}
void setname(string n)
{
    name =n;
}
void setschool(string s)
{
    school =s;
}
int getrollno()
    {
        return rollno;
    }
string getname()
{
    return getname;
}
string getschool()
{
    return school;
}
};
int main() …
Run Code Online (Sandbox Code Playgroud)

c++ string c++11

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

为什么我不能std :: partition这个std :: unordered_map?

这不构建,我不理解编译错误.

#include <unordered_map>
#include <algorithm>

int main()
{
    std::unordered_map<int, size_t> occurences = { { 10, 2 }, { 20, 5 }, { 30, 0 }, { 40, 5 }, { 50, 0 }, { 100, 9 } };

    auto newEnd = std::partition(occurences.begin(), occurences.end(), [](const std::pair<int, size_t> &p)
        {
        return p.second == 0;
        });

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

g ++抱怨如下.VS2013更加神秘.

/usr/local/include/c++/6.3.0/bits/stl_pair.h:实例化'void std :: pair <_T1,_T2> :: swap(std :: pair <_T1,_T2>&)[与_T1 = const int; _T2 = long unsigned int]':/ usr/local/include/c + +/6.3.0 /bits/stl_pair.h:473:7:从'void …

c++ stl-algorithm

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

C++中构造函数的条件

这个条件在构造函数中是正确的还是有更好的方法来做到这一点?

class Foo {
    public: Foo(int y) {
        if (y < 0 || y > 99)
           cout << "Error! Invalid input" << endl;

        else
            x = y;
        }

    private: int x;
    };
Run Code Online (Sandbox Code Playgroud)

c++ constructor

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

理解指针教程的问题

此代码取自cplusplus.com.它在教程中用于解释指针,我很难理解.

当他们写p1 = 20时; 在代码的末尾,是否会改变第一个值的内存地址以及第二个值?因为他们之前已经在代码中创建了p1 = p2.

如果有人有不同的解释方式,除了他们对网站或其他教程的评论?

谢谢!

#include <iostream>
using namespace std;

int main ()
{
  int firstvalue = 5, secondvalue = 15;
  int * p1, * p2;

  p1 = &firstvalue;  // p1 = address of firstvalue
  p2 = &secondvalue; // p2 = address of secondvalue
  *p1 = 10;          // value pointed to by p1 = 10
  *p2 = *p1;         // value pointed to by p2 = value pointed to by p1
  p1 = p2;           // p1 = …
Run Code Online (Sandbox Code Playgroud)

c++ pointers

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