Search Results

Search found 3 results on 1 pages for 'justik'.

Page 1/1 | 1 

  • Test, if object was deleted

    - by justik
    Look to the following code, please: class Node { private: double x, y; public: Node (double xx, double yy): x(xx), y(yy){} }; int main() { Node *n1 = new Node(1,1); Node *n2 = n1; delete n2; n2 = NULL; if (n1 != NULL) //Bad test { delete n1; //throw an exception } } There are two pointers n1, n2 pointed to the same object. I would like to detect whether n2 was deleted using n1 pointer test. But this test results in exception. Is there any way how to determine whether the object was deleted (or was not deleted) using n1 pointer ? Thanks for your help.

    Read the article

  • C++, array declaration, templates, linker error

    - by justik
    There is a linker error in my SW. I am using the following structure based on h, hpp, cpp files. Some classes are templatized, some not, some have function templates. Declaration: test.h #ifndef TEST_H #define TEST_H class Test { public: template <typename T> void foo1(); void foo2 () }; #include "test.hpp" #endif Definition: test.hpp #ifndef TEST_HPP #define TEST_HPP template <typename T> void Test::foo1() {} inline void Test::foo2() {} //or in cpp file #endif CPP file: test.cpp #include "test.h" void Test::foo2() {} //or in hpp file as inline I have the following problem. The variable vars[] is declared in my h file test.h #ifndef TEST_H #define TEST_H char *vars[] = { "first", "second"...}; class Test { public: void foo(); }; #include "test.hpp" #endif and used as a local variable inside foo() method defined in hpp file as inline. test.hpp #ifndef TEST_HPP #define TEST_HPP inline void Test::foo() { char *var = vars[0]; //A Linker Error } #endif However, the following linker error occurs: Error 745 error LNK2005: "char * * vars" (?vars@@3PAPADA) already defined in test2.obj How and where to declare vars[] to avoid linker errors? After including #include "test.hpp" it is late to declare it...

    Read the article

  • C++, inject additional data in a method

    - by justik
    I am adding the new modul in some large library. All methods here are implemented as static. Let mi briefly describe the simplified model: typedef std::vector<double> TData; double test ( const TData &arg ) { return arg ( 0 ) * sin ( arg ( 1 ) + ...;} double ( * p_test ) ( const TData> &arg) = &test; class A { public: static T f1 (TData &input) { .... //some computations B::f2 (p_test); } }; Inside f1() some computations are perfomed and a static method B::f2 is called. The f2 method is implemented by another author and represents some simulation algorithm (example here is siplified). class B { public: static double f2 (double ( * p_test ) ( const TData &arg ) ) { //difficult algorithm working p_test many times double res = p_test(arg); } }; The f2 method has a pointer to some weight function (here p_test). But in my case some additional parameters computed in f1 for test() methods are required double test ( const TData &arg, const TData &arg2, char *arg3.... ) { } How to inject these parameters into test() (and so to f2) to avoid changing the source code of the f2 methods (that is not trivial), redesign of the library and without dirty hacks :-) ? The most simple step is to override f2 static double f2 (double ( * p_test ) ( const TData &arg ), const TData &arg2, char *arg3.... ) But what to do later? Consider, that methods are static, so there will be problems with objects. Thanks for your help.

    Read the article

1