标签: c++03

如何在C++ crossplatform snprintf中实现?

我想知道是否有可能以及如何在C++ crossplatform中实现(C99,C++ 0x独立)snprintf?有没有这样的提升?(我想知道要替换的C++习语是snprintf(4)什么?)

c++ boost c++03

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

什么是C++ 03宏?

我正在尝试使用编译库-std=c++03,但编译失败,因为nullptr_t未定义.

如何使用硬编码宏保证C++ 03而不是C++ 11编译?

提前致谢.

c c++ macros c++03

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

C++字符串输出引用参数或返回值,是否有最佳方法?

示例代码:

class Thingy
{
public:
    void doStuff(std::string&);
    std::string doStuff();
};

void Thingy::doStuff(std::string& str) {
    str = "stuff";
}

std::string Thingy::doStuff() {
    return "stuff";
}

int main(int argc, const char* args[])
{
    std::string name;
    Thingy thingy;
    thingy.doStuff(name);
    std::cout << name << " " << thingy.doStuff() << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

特别是对于字符串,要么是方法更有效,那么效率"值得"来扭曲代码的可读性或一致性?(例如,如果我不需要,我宁愿不创建名称变量)

事实上,这是(在一天结束时)与此讨论相关的字符串常量吗?

c++ c++11 c++03

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

C++矩阵乘法类型检测

在我的C++代码中,我有一个Matrix类,并且编写了一些运算符来乘以它们.我的类是模板化的,这意味着我可以有int,float,double ...矩阵.

我猜运算符过载是经典的

    template <typename T, typename U>
    Matrix<T>& operator*(const Matrix<T>& a, const Matrix<U>& b)
    {
    assert(a.rows() == b.cols() && "You have to multiply a MxN matrix with a NxP one to get a MxP matrix\n");
    Matrix<T> *c = new Matrix<T>(a.rows(), b.cols());
    for (int ci=0 ; ci<c->rows() ; ++ci)
    {
      for (int cj=0 ; cj<c->cols() ; ++cj)
      {
        c->at(ci,cj)=0;
        for (int k=0 ; k<a.cols() ; ++k)
        {
          c->at(ci,cj) += (T)(a.at(ci,k)*b.at(k,cj));
        }
      }
    }
    return *c;
  }
Run Code Online (Sandbox Code Playgroud)

在这段代码中,我返回一个与第一个参数相同类型的矩阵,即Matrix<int> * Matrix<float> …

c++ templates c++03

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

算术表达式可以作为参数传递给函数以描述其中的逻辑吗?

我正在可视化Mandelbrot集以及其他一些分形,并且有很多重复的代码,但是没有代码重用。

我正在使用的功能之一如下:

/**
 * determines whether a pixel lies in the set
 * @params x, y - x and y coordinates on R/I axes
 * @param c - a complex number
 */
void calculateSet(int x, int y, Complex c) {
    Complex z = c.clone();
    int n = 0;
    for (; n < maxDepth; n++) {
        if (z.dis() > 4) { break; }
        z = z^2 + c;
    }
    // some code using n to color the set
}
Run Code Online (Sandbox Code Playgroud)

这遵循Mandelbrot集:

z_(n+1) …
Run Code Online (Sandbox Code Playgroud)

c++ polymorphism expression class c++03

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

基类可以声明一个虚方法而不定义它吗?仍然在派生类中定义

#include <vector>

class M {
    public:
        M(unsigned int);
        unsigned int n;
};

M::M(unsigned int i) { n = i; }

class A {
    protected:
        char t;
    public:
        virtual ~A();
        virtual std::vector<M> foo(unsigned int);
        char getChar();
};

A::~A(){}
std::vector<M> A::foo(unsigned int u) {
    std::vector<M> v;
    return v;
}
char A::getChar() { return t; }

class B : public A {
    public:
        B();
        std::vector<M> foo(unsigned int);
};

B::B() { t = 'b'; }
std::vector<M> B::foo(unsigned int c) {
    std::vector<M> v;
    for (unsigned …
Run Code Online (Sandbox Code Playgroud)

c++ virtual abstract-class c++03

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

哪个c ++容器可以包含C int多维数组(C++ 03/MSVC11)?

我有这个多维2阵列

int anArray1[MAX_ROW][MAX_CELL] =
{
    { 0, 1, 1, 0, 1, 1, 1, 0},
    { 0, 1, 1, 0, 1, 1, 1, 0},
    { 0, 1, 1, 0, 1, 1, 1, 0},
    { 0, 1, 1, 0, 1, 1, 1, 0},
    { 0, 0, 0, 0, 0, 0, 0, 0}
}


int anArray2[MAX_ROW][MAX_CELL] =
{
    { 0, 1, 1, 0, 1, 1, 1, 0},
    { 0, 1, 1, 0, 1, 1, 1, 0},
    { 0, 1, 1, 0, 1, 1, …
Run Code Online (Sandbox Code Playgroud)

c++ containers multidimensional-array c++03 visual-studio-2012

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

围绕"未定义/无效"枚举C++的C++设计

假设我有以下枚举.

enum VehicleType
{
    CAR,
    PLANE,
    UNDEFINED
};
Run Code Online (Sandbox Code Playgroud)

现在在Vehicle中(想象一个具有VehicleType变量的简单类); 默认构造函数我必须为车辆分配一些车型.不知道它是什么,我不想把它称为汽车或飞机,所以我称之为未定义.

这会给枚举用户带来负担,因为他们必须考虑如何处理未定义的类型.如果我想摆脱UNDEFINED,我在C++ 03中的选择是什么?

我可以考虑重新设计,以便默认构造函数根本不可用,但由于大局,这似乎不太可行.

编辑:这个问题比问题复杂得多.但问题的答案是正确的,所以我会接受.:)

c++ enums c++03

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