1

I have a SaleItem class that has a pointer of an another class Product Category as member function, the getter of the SaleItem class that returns the pointer to the ProductCategory is causing the error. The IDE does not give the error straightaway but when I build the the C++ codebase; the SWIG interface interprets the c++ code for me in the build process. We interface the C++ to Perl using SWIG when it is done, in that particular section the error is thrown.

  1. The first excerpt of code is from the SALEITEM class
  2. The second is the Command Line text the describes the ERRORS
  3. The third section is the Product Category Class summary
  4. Fourth and the final is the SWIG interpretation.

The Section of the code that is at the bottom of this question is where the Terminal refers the error. But I believe it is in my C++ code. I have done all that I know in my knowledge to fix this issue. Therefore seeking your help

/**
 * @brief returns the saleItem's Product Category Details in a pointer
 * @return ProductCategory*
 *
 */

ProductCategory* SaleItem::getProductCategory(){
    return m_productCategory.get();
}


private:
        /**
         * @brief load SaleItem object from pc_sale_item table.
         * 
         * @param SaleItemId
         * 
         * @return true
         * @return false
         * 
         */
        bool _load(const string& pId);
    private:
        std::vector<shared_ptr<SaleItemCommission>> vCommissions;
        unique_ptr<Contract> pRetailerContract;
        unique_ptr<Contract> pServiceContract;
        std::vector<std::string> _vTags;
        unique_ptr<ProductCategory> m_productCategory;
        std::string m_groupNum;
    };
}


The Above is the SaleItem Class, the error is throwing at the function getProductCategory()




/home/rrajan/public_html/cms/src/cms_xl/build/swig/CMakeFiles/sale.dir/salePERL_wrap.cxx: In function ‘void _wrap_SaleItem_getProductCategory(PerlInterpreter*, CV*)’:
/home/rrajan/public_html/cms/src/cms_xl/build/swig/CMakeFiles/sale.dir/salePERL_wrap.cxx:23133:5: error: ‘ProductCategory’ was not declared in this scope
     ProductCategory *result = 0 ;
     ^~~~~~~~~~~~~~~
/home/rrajan/public_html/cms/src/cms_xl/build/swig/CMakeFiles/sale.dir/salePERL_wrap.cxx:23133:5: note: suggested alternative:
In file included from /home/rrajan/public_html/cms/src/cms_xl/swig/../src/../src/sale/SaleItem.h:19:0,
                 from /home/rrajan/public_html/cms/src/cms_xl/build/swig/CMakeFiles/sale.dir/salePERL_wrap.cxx:2119:
/home/rrajan/public_html/cms/src/cms_xl/swig/../src/../src/sale/../core/ProductCategory.h:33:8: note:   ‘Cms::ProductCategory’
  class ProductCategory: public Virtual::Base
        ^~~~~~~~~~~~~~~
/home/rrajan/public_html/cms/src/cms_xl/build/swig/CMakeFiles/sale.dir/salePERL_wrap.cxx:23133:22: error: ‘result’ was not declared in this scope
     ProductCategory *result = 0 ;
                      ^~~~~~
/home/rrajan/public_html/cms/src/cms_xl/build/swig/CMakeFiles/sale.dir/salePERL_wrap.cxx:23133:22: note: suggested alternative: ‘res1’
     ProductCategory *result = 0 ;
                      ^~~~~~
                      res1
/home/rrajan/public_html/cms/src/cms_xl/build/swig/CMakeFiles/sale.dir/salePERL_wrap.cxx:23146:36: error: expected primary-expression before ‘)’ token
         result = (ProductCategory *)(arg1)->getProductCategory();
                                    ^
make[2]: *** [CMakeFiles/sale.dir/build.make:83: CMakeFiles/sale.dir/CMakeFiles/sale.dir/salePERL_wrap.cxx.o] Error 1



The above is the Command line Errors that are thrown Below is a the class Product Category

class ProductCategory: public Virtual::Base
    {
        public:
        /**
         * @brief Construct a new Product Category object
         *
         * @param sProductId
         */
        ProductCategory(){}

        /**
         * @brief Construct a new Product Category object
         * @param sProductId
         */
        ProductCategory(string productID);

        /**
         * @brief Destructs a Product Category object
         *
         */
        ~ProductCategory(){}

The SWIG Interpretation of the SaleITEM::getProductcategory() is the below code


XS(_wrap_SaleItem_getProductCategory) {
  {
    Cms::SaleItem *arg1 = (Cms::SaleItem *) 0 ;
    void *argp1 = 0 ;
    int res1 = 0 ;
    int argvi = 0;
    ProductCategory *result = 0 ;
    dXSARGS;
    
    if ((items < 1) || (items > 1)) {
      SWIG_croak("Usage: SaleItem_getProductCategory(self);");
    }
    res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_Cms__SaleItem, 0 |  0 );
    if (!SWIG_IsOK(res1)) {
      SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SaleItem_getProductCategory" "', argument " "1"" of type '" "Cms::SaleItem *""'"); 
    }
    arg1 = reinterpret_cast< Cms::SaleItem * >(argp1);
    {
      try {
        result = (ProductCategory *)(arg1)->getProductCategory();
      }
      catch (sql::SQLException &) {
        croak("SQL exception");
      }
    }
    ST(argvi) = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_ProductCategory, 0 | 0); argvi++ ;
    
    XSRETURN(argvi);
  fail:
    
    SWIG_croak_null();
  }


rrajanuk
  • 27
  • 8
  • root cause seems to be "‘ProductCategory’ was not declared in this scope". Please post a [mcve], perhaps you just forgot to include a header – 463035818_is_not_an_ai Sep 14 '20 at 07:58
  • Header file is included in the SaleItem scope....the environment set up is different hence I don't know how to post a reproducible example.. – rrajanuk Sep 14 '20 at 08:10
  • `salePERL_wrap.cxx` does not include the file defining `ProductCategory`, does it? – Ted Lyngmo Sep 14 '20 at 08:28
  • I cannot confirm that the file is included or not. Basically my understanding is that the source files is automatically interpreted to the salePERL_wrap.cxx ; so in that case I am assuming that the ProductCategory is included – rrajanuk Sep 14 '20 at 08:50
  • @RobinRajan But you can open `/home/rrajan/public_html/cms/src/cms_xl/build/swig/CMakeFiles/sale.dir/salePERL_wrap.cxx` to check if it does `#include `, right? – Ted Lyngmo Sep 14 '20 at 10:00
  • @TedLyngmo this is the ```#define SWIGTYPE_p_ProductCategory swig_types[32]``` It is included but it is included in this form not as we include in the CPP Source Files – rrajanuk Sep 15 '20 at 02:33
  • You misunderstood what I asked. I was asking if you can open the file `.../salePERL_wrap.cxx`. – Ted Lyngmo Sep 15 '20 at 05:46
  • Yes I can open that file ....and also I have updated the Title of the issue to make this problem specific – rrajanuk Sep 15 '20 at 07:02
  • (I won't get a notification that you've answered me unless you use the tagging functionality. That is, type @TedLyngmo when you answer). Ok, so you can open `salePERL_wrap.cxx`. Does it contain the line `#include "the file in which ProductCategory is defined"` or does it contain the definition of `ProductCategory` itself? What is the name of the source code file in which `SaleItem` is defined? Does that file contain a line like `#include "the file in which ProductCategory is defined"`? It would be easier if you put the names of your files in the question and also if you made a [mcve]. – Ted Lyngmo Sep 15 '20 at 13:20

1 Answers1

1

So Finally, I found the answer... For some reason although the ProductCategory class definition that is in the namespace called Cms, which is also the same namespace of the SaleItem class definition that held an object instance of ProductCategory class still was not in the scope.

The SaleItem class was responsible to throw that ERROR stating that ProductCategory instance in its class is not in the SCOPE of SaleItem.

To solve this ERROR I found that, if I add Cms::ProductCategory to the getter method of the SaleItem class, the SaleItem class realizes immediately that ProductCategory Object is in the same scope.

   /**
    * @brief returns the saleItem's Product Category Details in a pointer
    * @return ProductCategory*
    *
    */

    Cms::ProductCategory* SaleItem::getProductCategory(){
      return m_productCategory.get();
    }

The addition of Cms:: solved the error.

One more thing that I found is that there were other Object Instances in the same SaleItem class such as a Contract class Object; but when the Contract Object's instance getter was declared in the SaleItem class it did not throw an error although there was no addition of Cms:: behind it.

/**
     * @brief returns a pointer to the associated contract object
     * this function make sures that returned pointer is not NULL
     * saves the system from crashing
     * @return Contract*
     *
     */
    Contract* getContract();

I then found in the Contract class certain declarations that I did not understand, but I think they make sure that Contract is in the scope of SaleItem. So, Hence the Contract object does not throw the same errors as ProductCategory did.

Below are those declarations lines..

 namespace Cms
    {
       class Sale;
       class SaleItem;

       /**
        * @brief A contract class. Which has contract related information.
        * This is mainly used as an interface for service contract and retailer contract.
        * It is derived from Base.
        *
        */
        class Contract : public Virtual::Base {
        }
    }

I hope this will be useful for somebody who comes across this. May be somebody else can give more explanation to it.

rrajanuk
  • 27
  • 8