most-vexing-parse

    24热度

    1回答

    我从here得到的代码。 class Timer { public: Timer(); }; class TimeKeeper { public: TimeKeeper(const Timer& t); int get_time() { return 1; } }; int main() { TimeKeep

    3热度

    3回答

    基本上这是关于最令人头疼的解析的this question的后续。我可以理解这是由于函数声明和变量定义之间的不明确性。 但在Comeau在线,我只是厌倦了以下。 class T{ public: T(int i){ } int fun1(){ return 1; } }; int main() { T myT(10);

    7热度

    1回答

    我有一个构造函数的问题,它不像我所期望的那样工作。 如果我尝试初始化我的课一样,它会工作,我得到一个可用的对象: vector<float> v; MyClass<2> a(v); 但是,如果我尝试建立类似下面的一类(这应该是等同)的结果是非常意外的。编译或运行程序时没有错误消息/警告。但是如果你试图在某个地方使用这个变量并调用它的方法(例如a.doSomething()),它会崩溃。 我在

    5热度

    3回答

    我有一个向量,我正试图执行包含功能。我正在收到某种投射错误,我无法拼凑出一个解决方案。我也想知道我在做什么是检查矢量是否包含值的适当方法。 下面是代码: #include "stdafx.h" #include <vector> static void someFunc(double** Y, int length); static bool contains(double value,

    2热度

    3回答

    我试图编译这个代码片段,但我得到了编译器错误:(与Visual Studio编译2010 #include <vector> #include <string> #include <sstream> #include <iterator> #include <iostream> using namespace std; int main() { string s("Wel

    2热度

    2回答

    我想了解如何显式构造函数调用主要使用下面的代码工程。 #include<iostream> using namespace std; class Dependency1 { bool init; public: Dependency1() : init(true) { std::cout << "Dependency1 construction"

    11热度

    6回答

    可能重复: Why is it an error to use an empty set of brackets to call a constructor with no arguments? 让我们有这样的代码 class Foo { Foo(int) { } }; 那么我们有没有结果: int main() { Foo f1 = Foo(5); // 1: OK,

    15热度

    4回答

    在下面的代码中,为什么编译器不会抱怨mClass2? class CMyClass{ private: CMyClass(){} }; void TestMethod(){ CMyClass mClass1; //Fails. CMyClass mClass2(); //Works. }

    7热度

    2回答

    我有一个示例代码如下。 #include<iostream> template<typename T> class XYZ { private: T & ref; public: XYZ(T & arg):ref(arg) { } }; class temp { int x; public: t

    0热度

    3回答

    在构造函数的定义print语句不打印它的typeid的,没有构造函数调用正确的主?我知道我在这里错过了一些观点,请指出。 #include <iostream> #include <typeinfo> template <typename T> class List { public: template <typename T2> List (List<T2> con