小编Tro*_*our的帖子

运算符重载的c ++多态性

如何使纯虚函数成为运算符+(); 功能.whehı在基类int operator +()= 0中这样做; 编译器给出错误.在派生类运算符+()函数编译器中说派生类不能使.因为下面的类是抽象的,我知道我不能创建抽象类的对象,但现在我尝试创建派生类对象.

这是代码

#include <iostream>
using namespace std;
class ana {
    protected :
    int x;

    public :
    virtual int operator+()=0;
    virtual void operator=(ana&)=0;
    };

class baba : public ana{
    public:
    baba(int k){x=k;}
    int   operator+(baba &ali){
        int k;
        k=x+ali.x;
        return k;
    }
   void operator=(baba &ali){
       x=ali.x;
       }


    };

int main(){
    baba k(4);

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

c++ polymorphism abstract-class operator-overloading

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

Qt和C++ - 对槽的未定义引用

我在Qt中有一个插槽的构建错误.我有一个有公共插槽的课程:

void doSomething();
Run Code Online (Sandbox Code Playgroud)

在这个类的构造函数中我做:

this->connect( ui->textFrom, SIGNAL(returnPressed()),
               this, SLOT(doSomething()) );
Run Code Online (Sandbox Code Playgroud)

我有QLineEdit - textFrom对象.构建错误是

../moc_mainwindow.cpp:66: undefined reference to `MainWindow::doSomething()'
Run Code Online (Sandbox Code Playgroud)

:-1:错误:collect2:ld返回1退出状态

请帮帮我 (:

c++ qt signals-slots undefined-reference

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

数学图形到方程

是否有工具将方程的图形表示转换为该方程式?(图形表​​示为aprox.数学方程式)

math graph

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

OpenGL/glut/stdc ++构建错误

我正在使用Ubuntu并尝试使用synaptic安装其中包含"GLUT"一词的所有内容以及SDL和opengl.但仍然是一个简单的程序无法编译.它显示了这个:

opengl1.cpp:(.text+0xe): undefined reference to `glClear'
opengl1.cpp:(.text+0x1a): undefined reference to `glBegin'
opengl1.cpp:(.text+0x2e): undefined reference to `glVertex2i'
opengl1.cpp:(.text+0x33): undefined reference to `glEnd'
opengl1.cpp:(.text+0x38): undefined reference to `glFlush'
/tmp/ccnwQeLu.o: In function `MyInit()':
opengl1.cpp:(.text+0x4c): undefined reference to `glGetString'
opengl1.cpp:(.text+0x57): undefined reference to `std::cout'
opengl1.cpp:(.text+0x5c): undefined reference to `std::basic_ostream >& std::operator >(std::basic_ostream >&, unsigned char const*)'
opengl1.cpp:(.text+0x6c): undefined reference to `std::basic_ostream >& std::operator >(std::basic_ostream >&, char const*)'
opengl1.cpp:(.text+0x78): undefined reference to `glGetString'
opengl1.cpp:(.text+0x83): undefined reference to `std::cout'
opengl1.cpp:(.text+0x88): undefined reference to `std::basic_ostream >& std::operator …

c++ opengl glut linker-errors

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

使用 gdb 进入 swapcontext()

我正在做一个进行unix系统调用的项目。具体来说,我的项目严重依赖对 getcontext()、makecontext()、swapcontext() 和 setcontext() 的调用。我尝试使用 gdb 调试我的代码。我逐行进入代码并检查了控件,但是一旦调用了 swapcontext(),它就不再进入代码了。相反,调试几乎就此停止,程序的其余部分会自动运行,而不是逐行运行。我猜 gdb 不会进入上下文调用?有什么办法可以解决这个问题吗?有没有可以用于此目的的调试器?谢谢

c unix linux gdb system-calls

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

Visual Studio 2010中的boost :: thread编译错误

我在很长一段时间内第一次尝试使用boost,当我包含boost/thread.hpp标头时,我在boost本身内部出现了编译错误:

    c:\myproj\boost_1_46_0\boost\thread\win32\thread_heap_alloc.hpp(97): error C2061: syntax error : identifier 'heap_memory
    c:\myproj\boost_1_46_0\boost\thread\detail\thread.hpp(134) : see reference to function template instantiation 'T *boost::detail::heap_new<boost::detail::thread_data<F>,void(__cdecl *)(void)>(A1 &&)' being compiled
    with
    [
        T=boost::detail::thread_data<void (__cdecl *)(void)>,
        F=void (__cdecl *)(void),
        A1=void (__cdecl *)(void)
    ]`
Run Code Online (Sandbox Code Playgroud)

这只是通过包含标题,它似乎与我的代码没有任何关系,但我看不出该怎么办,有人可以帮忙吗?

c++ multithreading boost visual-studio-2010

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

将QLineEdit添加到qtcreator中的qtoolbar(设计器)

嘿伙计们,我无法通过IDE本身将控件作为QLineEdit添加到QToolbar而不是添加代码(如果没有WYSIWYG编辑器,我无法进行任何GUI编码)

我也想帮助重叠控件.

另一个问题是如何通过悬停它来获取QWebview的链接(更像是当Web浏览器显示您悬停的链接时).

很抱歉提出太多问题我是你知道的新手.

提前致谢

c++ qt qt-creator qwebview qt-designer

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

fprintf调试断言失败

如果我手动启动它,我有一个正确运行的程序.但是,如果我尝试添加注册表项以在启动期间自动启动它,我会收到此错误:

Debug assertion failed (str!=null) fprintf.c line:55
Run Code Online (Sandbox Code Playgroud)

在发生任何事情之前我试图添加Sleep(20000),但是我得到了同样的错误.

这是代码:

main()
{
    FILE* filetowrite;
    filetowrite = fopen("textfile.txt", "a+");

    writefunction(filetowrite);
}

int writefunction(FILE* filetowrite) {

    fprintf(filetowrite, "%s", "\n\n");
    ...
}
Run Code Online (Sandbox Code Playgroud)

我也试过传递文件名char*并打开它writefunction(),但我得到了同样的错误.

c++ printf fopen assertions

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

G ++中的匿名函程?

我有一些代码可以在VS2008中工作,但不能在G ++中工作:

struct IIterationFunctor
{
    virtual bool operator()( SStateInfo& rStateInfo ) = 0;
    virtual ~IIterationFunctor() { }
};

struct SNumItemsFunctor : public IIterationFunctor
{
    SNumItemsFunctor (uint8& nNumItems, uint8 nItemType )
        : m_nNumItems (nNumItems)
        , m_nItemType (nItemType)
    {
        m_nNumItems = 0;
    }

    virtual bool operator() ( SStateInfo& rStateInfo )
    {
        if( rStateInfo.sState.nItemType == m_nItemType )
        {
            ++m_nNumItems;
        }
        return true;
    }

    uint8& m_nNumItems;
    uint8 m_nItemType 
};

void IterateStateInfo( IIterationFunctor& functor )
{
    for (TStateInfoIterator itStateInfo = m_lstStateInfos.Begin(); 
        itStateInfo != m_lstStateInfos.End(); 
        itStateInfo++) …
Run Code Online (Sandbox Code Playgroud)

c++ g++ functor

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

从Qstring转换为std :: string会引发异常

令人惊讶的是,下面的代码抛出异常.

QString qtemp = QDir::tempPath(); 
std::string temp = qtemp.toStdString();  
std::cout<<temp<<std::endl;
Run Code Online (Sandbox Code Playgroud)

当我使用visual studio调试时 - 我去了变量的值qtemp.但是在接下来的步骤中,我从调试器中获得了一个BAD指针,当我输出相同的时候会导致异常.

c++ qt4

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

Makefile:运行'make all'时出错

当我运行make all rule中指定的相同gcc命令时,我没有收到任何错误.但是当我运行make all时,我会遇到一堆错误.为什么会这样?

Makefile文件:

all: program.c
      gcc -I$HOME/ffmpeg/include program.c -L$HOME/ffmpeg/lib -lswscale -lavdevice -lavfilter -lswscale -lswresample -lavformat -lavcodec -lavutil -lz -lm -lpthread -o program
Run Code Online (Sandbox Code Playgroud)

运行gcc命令:

 (No error)
Run Code Online (Sandbox Code Playgroud)

跑步全部:

gcc -IOME/ffmpeg/include program.c -LOME/ffmpeg/lib -lswscale -lavdevice -lavfilter -lswscale -lswresample -lavformat -lavcodec -lavutil -lz -lm -lpthread -o program
program.c:15:32: error: libavcodec/avcodec.h: No such file or directory
program.c:16:32: error: libswscale/swscale.h: No such file or directory
program.c:17:34: error: libavformat/avformat.h: No such file or directory
program.c:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' …
Run Code Online (Sandbox Code Playgroud)

c c++ compiler-construction gcc

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