Posts

Showing posts with the label class

Why is std::string and std::vector not being passed to my constructor how I would expect? [duplicate]

Why is std::string and std::vector not being passed to my constructor how I would expect? [duplicate] This question already has an answer here: This is my error when trying to compile: Undefined symbols for architecture x86_64: "Model::Model(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::vector<int, std::__1::allocator<int> >)", referenced from: ____C_A_T_C_H____T_E_S_T____4() in tests.cpp.o I have read that std::string is a typedef of std::basic_string and I'm guess that std::vector is a typedef of... std::vector and std::allocator? or something... Anyway. I have a Settings class that holds my settings and a Model class that contains my model. The code I am attempting to run is as below, and I am unable to compile it. the issue is with it not recognising my model constructor. Settings s = Settings("../config/settings.json"); std::string mf = s.get_model_file(); std::vector<in...

How to destroy a class object in PHP?

How to destroy a class object in PHP? I wrote a little class for storing global variables/functions. My question is - is it necessary to destroy the class object after the script has finished? or will PHP destroy that object itself? Here's my code: $web=new c_web("myWeb"); $web->loadTemplate("/!framework/admin/template.htm"); $web->doStuff(); // script has finished - destroying required here? In case I need to destroy it, how can I do that? 3 Answers 3 If the script finishes, the memory is released. You're ready as is :) great - thanks! and what about if a script will will be terminated by an error? will all variables (database ..) be destroyed aswell? – Fuxi Apr 8 '11 at 11:34 Well, the d...

How to use class variables?

How to use class variables? A simple question. If I have class A with methods m1 and m2 . Is it a good practice that m1 changes the state of A . And then when m2 is called it relies on A 's state being changed by m1 . In other words if m2 is dependent on m1 being called before m2 being called. With m1 and m2 being both private. Worded differently is it O.K. for private methods to consider the object state as shared memory? Problem arises when they are called out of order. But with the benefit of not having to copy arguments. Any advice? 1 Answer 1 Your description is not a good design. Class variables should have class invariants that are true before and after any (and all) method invocations. The order of calls should not matter. The way you described it make is sounds that there will be cases during which this will not be true, for example if m1 is not called yet and m2 is. Moreover...