constructor

Copy Constructor with assignment overloading syntax?

半腔热情 提交于 2019-12-11 00:21:31
问题 I am working with writing the big five(copy constructor, copy assignment operator, move constructor, move assignment operator, destructor). And I've hit a bit of a snag with the copy constructor syntax. Say I have a class foo that has the following private members: template<class data> // edit class foo{ private: int size, cursor; // Size is my array size, and cursor is the index I am currently pointing at data * dataArray; // edit } If I were to write a constructor for this of some arbitrary

Scala “constructor Stopwatch cannot be accessed in class Main”

我是研究僧i 提交于 2019-12-11 00:06:45
问题 Summary on resolution, I thought I was dealing with a Scala problem but it turns out Stopwatch and Scala Logging have private constructors, and I was not calling the proper public methods to instantiate them. gzm0's answer below points this out. Trying to use Guava Stopwatch and Scala Logging, no matter whether I create a new Stopwatch() or new Logger() in Main or in an instantiated class I get this error with gradle run : constructor Logger in class Logger cannot be accessed in class

Template Error: no appropriate default constructor available

限于喜欢 提交于 2019-12-11 00:05:48
问题 The thing is, I am not (knowing trying to use any default constructor of beatle::beatle the error: 1> ecosystem.cpp 1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(172): error C2512: 'beatle::beatle' : no appropriate default constructor available 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(165) : while compiling class template member function 'beatle &std::map<_Kty,_Ty>::operator [](int &&)' 1> with 1> [ 1> _Kty=tokenID, 1> _Ty=beatle 1> ] 1> c:

Multiple optional arguments in constructor in Java - exponential number of constructors

亡梦爱人 提交于 2019-12-10 23:57:55
问题 This is something I've encountered a few times and haven't been able to find a satisfying answer yet. This seems pretty stupid, but after googling this for a while I couldn't come up with something good. Let's say I have a class with 20 instance variables, each of which is optional (will be initialized or not). Now I want my constructor(s) to handle all the cases, in case of a few instance variables it's fine and I can just create constructors with different signatures, but here I have 20, so

How do Action class constructors work with Struts2?

冷暖自知 提交于 2019-12-10 23:57:10
问题 I am directly forwarded to a method within my action class (by struts.xml) but I do not actually create a new instance of my Action Class. I ask because I have some variables to set before anything can be done with the ActionClass, and I thought constructors might help me do just that. 回答1: Struts 2 provides a Prepare Interceptor to prepare your data before the actual execute method runs.This interceptor calls prepare() on actions which implement Preparable. Some of the use cases for using

Constructors accepting string reference. Bad idea?

狂风中的少年 提交于 2019-12-10 23:15:36
问题 It's considered a bad idea/bad design, have a class with a constructor accepting a reference, like the following? class Compiler { public: Compiler( const std::string& fileName ); ~Compiler(); //etc private: const std::string& m_CurrentFileName; }; or should I use values? I actually do care about performance. 回答1: If you used a value parameter in this case, you would have a reference in the class to a temporary, which would become invalid at some point in the future. The bad idea here is

How function resolution in prototype chain will work for Object.prototype as constructor

巧了我就是萌 提交于 2019-12-10 22:51:32
问题 I am referring to this article on Helephant.com, to learn how Javascript resolves functions in the prototype chain when called on objects. The article quotes, If the object doesn’t have the method set directly on it, javascript then looks for a Constructor function that created the object. Javascript checks the constructor’s prototype property for the method. In the following code, if you check rufus.constructor is the global Object() constructor, so will JS directly check the global Object()

C++ Templates: implicit conversion, no matching function for call to ctor

柔情痞子 提交于 2019-12-10 22:02:16
问题 template<class T> class test { public: test() { } test(T& e) { } }; int main() { test<double> d(4.3); return 0; } Compiled using g++ 4.4.1 with the following errors: g++ test.cpp -Wall -o test.exe test.cpp: In function 'int main()': test.cpp:18: error: no matching function for call to 'test<double>::test(double) ' test.cpp:9: note: candidates are: test<T>::test(T&) [with T = double] test.cpp:5: note: test<T>::test() [with T = double] test.cpp:3: note: test<double>::test(const test<double>&)

initialization ignores constructor templates

懵懂的女人 提交于 2019-12-10 21:24:34
问题 While pursuing some errors, I stumbled upon the following behavior of initialization, which seems odd to me: While initialization checks for existing constructors, there seem to be cases were templates for fitting constructors are ignored. Consider for example the following program: #include <iostream> template<class T> struct A { A() {}; template<class S> A(const A<S>& a) {std::cout << "constructor template used for A" << std::endl;}; }; template<class T> struct B{ B() {}; B(const B<int>& b)

no matching functions for call to constructor (c++) [duplicate]

穿精又带淫゛_ 提交于 2019-12-10 20:33:15
问题 This question already has answers here : What is an undefined reference/unresolved external symbol error and how do I fix it? (32 answers) Closed 6 years ago . EDIT Ok, I've done a bit of reading again for a few hours and I think I finally understand c++ OOP a bit better (at least the basics). I decided to rewrite the entire program and code a bit at a time and test more. I think i narrowed the errors i bit more this time. NamedStorm.h #include <string> #include <iostream> #ifndef NAMEDSTORM