小编Ara*_*raK的帖子

初级程序员可以用什么语言为它实现翻译?

我的大学即将开始,但我想在剩下的几周内做点什么:)

上学期我上了一门课程programming languages,我想把我的知识变为现实.有什么简单的,优雅的语言可以在初级程序员实施一个解释?

我不介意语言是非常小还是实验性的.

interpreter programming-languages

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

iostream使用<<来构造字符串

如何<<用于构造字符串ala

int iCount;
char szB[128];
sprintf (szB,"%03i", iCount);
Run Code Online (Sandbox Code Playgroud)

c++ iostream

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

神秘的oneliner模板代码,任何一个?

我正在阅读此页面: C++提示:如何获取数组长度.作者提出了一段代码来了解静态数组的大小.

template<typename T, int size>
int GetArrLength(T(&)[size]){return size;} // what does '(&)' mean ?
.
.
.
int arr[17];
int arrSize = GetArrLength(arr); // arrSize = 17
Run Code Online (Sandbox Code Playgroud)

任何人都可以阐明这段代码,因为我无法理解它是如何工作的.

c++ arrays templates metaprogramming

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

模板部分专业化 - 任何现实世界的例子?

我在思考partial specialization.虽然我理解这个想法,但我还没有看到这种技术的任何实际用法.Full specialization在很多地方使用,STL所以我没有问题.你能教育我一个真实世界的例子partial specialization吗?如果这个例子是STL优秀的!

c++ templates partial-specialization

4
推荐指数
2
解决办法
3118
查看次数

这是标准的C++代码吗?

下面简单的一段代码,用VC2008编译但g ++拒绝代码:

#include <iostream>

class myclass
{
protected:
    void print() { std::cout << "myclass::print();"; }
};

struct access : private myclass
{
    static void access_print(myclass& object)
    {
        // g++ and Comeau reject this line but not VC++
        void (myclass::*function) () = &myclass::print;

        (object.*function)();
    }
};

int main()
{
    myclass object;
    access::access_print(object);
}
Run Code Online (Sandbox Code Playgroud)

(/W4) 在VC中打开,但它没有给出任何警告.

g ++ 4.4.1给出了一个错误:

correct.cpp: In static member function ‘static void access::access_print(myclass&)’:
correct.cpp:6: error: ‘void myclass::print()’ is protected
Run Code Online (Sandbox Code Playgroud)

如果g ++是正确的,我如何访问类的受保护成员?有另一种方式吗?


@Suroot你是说我不应该传递类型的对象myclass?实际上并不重要,g ++给出了相同的错误,但VC编译代码时没有任何警告.

#include <iostream>

class …
Run Code Online (Sandbox Code Playgroud)

c++ standards standards-compliance

4
推荐指数
2
解决办法
335
查看次数

How to choose the "Key" for inter-processes communication in Linux?

Good Day...

I am doing a homework which states that I have 5 processes; a server and the rest are clients. Each process is supposed to be sparked from a different executable. I am going to implement a two-way message passing solution, but the question is not about message passing per se. Is there an elegant way to communicate the key between those different executables. i.e. when I call the following function:

int msgget(key_t key, int msgflg);
Run Code Online (Sandbox Code Playgroud)

How are …

linux ipc message-passing

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

哪个应该继承哪个?

这是一个无聊的学术OOP问题,但它不是一个功课.我从新手程序员那里得到了一个关于OOP的愚蠢教科书例子的问题.

想象一下,你正在设计一个Square类和一个Cube类,它应该继承哪个?

我看到了一段感情,但它是什么,我真的看不到!

你能不能给我一个关于OOP的逻辑论证.

oop puzzle

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

你如何让别人信任你的代码并使用它?

我不时写爱好代码.事情就是这些工具,类或微小的代码库最终会成为一个无望未来的闪存棒!我希望进一步发展我的项目,并让其他程序员信任他们.如果您要使用在Internet上找到的东西,那么您在该编程工具或小型库中寻找的最重要的东西是什么?你会考虑单独的文件吗?


感谢所有贡献者.我会尽力总结已经说过的话.随意修改列表.更正和补充更受欢迎:)

language-agnostic

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

项目欧拉问题#276 - 原始三角形

我试图从Project Euler解决问题#276,但到目前为止还没有成功.

考虑具有整数边a,b和c的三角形,其中a≤b≤c.如果gcd(a,b,c)= 1,则整数边三角形(a,b,c)称为基元.存在多少个原始整数边三角形,周长不超过10 000 000?

我的代码中的瓶颈是GCD功能.我的样本输入几乎占用了90%的执行时间.我很想听听关于如何改进解决方案的提示和评论...我的解决方案是用C语言编写的,但它很简单:

#include <stdio.h>
#include <math.h>

#define sides 3
// This is where my program spends most of its time
size_t bi_gcd (size_t a, size_t b);
size_t tri_gcd (size_t a, size_t b, size_t c);
size_t count_primitive_triangles (size_t maximum_perimeter);

int main()
{
 printf( "primitive_triangles = %lu \n",
            count_primitive_triangles(1000) );
}

size_t bi_gcd (size_t a, size_t b)
{
 size_t t;

 while(b != 0)
 {
  t = b;
  b = a % …
Run Code Online (Sandbox Code Playgroud)

c algorithm math performance

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

使用指针交换值

我有这个代码片段

int i = 5;
int k = 7;
int * iPtr;
int * jPtr;
int * kPtr;

iPtr = &i;
kPtr = &k;
Run Code Online (Sandbox Code Playgroud)

我需要使用指针交换i和k.这就是我这样做的方式:

*jPtr = *kPtr ;
*kPtr = *iPtr ;
*iPtr = *jPtr ;
Run Code Online (Sandbox Code Playgroud)

这是最好的方法吗,还是有更好的方法?

c++

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