A little confused about this

This is a discussion on A little confused about this within the C++ Programming forums, part of the General Programming Boards category; Code: class xsd__anyType { public: char *__item; }; class ArrayOf__xsd__anyType : public xsd__anyType { public: xsd__anyType **__ptr; int __size; }; ...

  1. #1
    Banned
    Join Date
    Nov 2007
    Posts
    678

    A little confused about this

    Code:
    class xsd__anyType {
    public:
        char *__item;
    };
    
    
    class ArrayOf__xsd__anyType : public xsd__anyType {
    public:
        xsd__anyType **__ptr;
        int __size;
    };

    Now I want to initialize a dynamic array (a pointer) that I have,
    Code:
    ArrayOf__xsd__anyType* properties;
    And I am lost

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    So, an array_of_something IS-A something?

  3. #3
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Yeah, that is the confusing part.
    Plus I am not able to find out, how to, initialize the properties array?

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by manav View Post
    Yeah, that is the confusing part.
    Seems broken to me. And....why not just use std::vector<any_type>?

  5. #5
    Banned
    Join Date
    Nov 2007
    Posts
    678
    I had a WSDL file, from which I created the above C++ code using a generator tool.
    And it is way too much work to build a handwritten client for that 5000+ lines WSDL file. So, I am using above auto-gen code. I just need to cope up with it. Somehow.

  6. #6
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,657
    Is this gSOAP perhaps? If so, docs are here. I can't be much help directly as I've only written a gSOAP server, and in pure C at that, but thought maybe a pointer (hah) to the docs might be helpful.

  7. #7
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Yes. This was generated by gSOAP. Thanks for link.

    And if some of the more experienced C++ users feel, that, the definitions created by gSOAP are ok, not necessarily a good example, but, if the definitions are correct and compilable, then, please let me know how to initialize the properties array here?

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    In essence, you want to set the value of
    char *__item;
    xsd__anyType **__ptr;
    int __size;
    When creating the class or array?
    This is not possible with dynamic memory to my knowledge.
    However, the solution is simple. Design a new function that sets all of these items in a class:

    Code:
    class A { public: int a, b, c; };
    
    void foo(A* pA, int a, int b, int c)
    {
    	pA->a = a;
    	pA->b = b;
    	pA->c = c;
    }
    
    int main()
    {
    	A* pA = new A[10];
    	for (int i = 0; i < 10; i++)
    		foo(pA, 1, 1, 1);
    	delete [] pA;
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Banned
    Join Date
    Nov 2007
    Posts
    678
    I could come up with this solution:
    Code:
    ArrayOf__xsd__anyType* properties = new ArrayOf__xsd__anyType;
    int size = 2;
    xsd__anyType** list = new xsd__anyType*[size];
    for (int i=0; i<size; i++) {
    	list[i] = new xsd__anyType;
    }
    
    list[0]->__item = qstrdup("url:whateveryoururlis");
    list[1]->__item = qstrdup("useFixed:1");
    
    properties->__ptr = list;
    properties->__size = size;
    Besides being messy. Is there anything else, conceptually, wrong here?

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    What the heck is qstrdup? I'd be worried if it allocates new memory using new/malloc. You've got too many pointers all over the place.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by Qt
    char * qstrdup ( const char * src )
    Returns a duplicate string.
    Allocates space for a copy of src, copies it, and returns a pointer to the copy. If src is 0, it immediately returns 0.
    Ownership is passed to the caller, so the returned string must be deleted using delete[].
    So I can delete it later using delete[]. But I need it to be working first.
    Tell me, if, there is, anything, wrong here in my initialization?

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    Too messy. Get a debugger and try. You're most likely going to have tons of memory leaks.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Memory leaks, for now, is a secondary issue. I will plug the holes, later.
    Messy, of course, so many manual allocations, no use of STL facility. But since WSDLs are programming language independent, so, I think my tool could not use better features from STL.

    Anyway. I am not getting anywhere. I just needed a confirmation, about, every thing being initialized properly.

    Thanks all.

  14. #14
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by manav View Post
    So I can delete it later using delete[]. But I need it to be working first.
    Tell me, if, there is, anything, wrong here in my initialization?
    Write a unit test for it. I'd recommend UnitTest++ as the test framework.

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    Language independent? How can anything be language independent?
    I'd really worry about getting some C++ tool instead of half-witted C crap that produces unreadable, unmaintainable code mess.
    Well, hopefully you'll have better luck next time you have to do something like this. You can always hope.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused about Memory
    By gL_nEwB in forum C++ Programming
    Replies: 22
    Last Post: 06-20-2006, 08:32 PM
  2. why wont this compile?!? :confused:
    By jdude in forum C++ Programming
    Replies: 5
    Last Post: 11-25-2004, 01:13 AM
  3. So Now Im getting confused?!?!?
    By zergdeath1 in forum C++ Programming
    Replies: 11
    Last Post: 03-06-2004, 05:41 PM
  4. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-04-2003, 02:21 PM
  5. Extern Question, really confused
    By SourceCode in forum C Programming
    Replies: 10
    Last Post: 03-26-2003, 11:11 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21