Thread: Creating a DLL, compilation problem

  1. #1
    Registered User Osaou's Avatar
    Join Date
    Nov 2004
    Location
    Stockholm, Sweden
    Posts
    69

    Creating a DLL, compilation problem

    Right, I'm trying to build a DLL using VSC++ 2005. I get numerous compilation errors, the first being "type 'int' unexpected", continuing with similarities such as "unexpected tokens preceding ';'".

    Here's the first reported erroneous file:

    (What the hell?)

    Code:
    #ifndef _OSAOU_SCRIPT_PARSER_HEAP_HPP_
    #define _OSAOU_SCRIPT_PARSER_HEAP_HPP_
    
    // INCLUDES
    
    #include <vector>
    
    
    
    // CLASS DECLARATION
    
    namespace osaou{
    	namespace script{
    		namespace parser{
    			class Variable;
    
    			class Heap{
    			public:
    
    				Heap(int index, size_type capacity);		<--- "type 'int' unexpected"
    				~Heap();
    
    				Variable* get(int v) const { return m_vars[v]; }
    				void remove(int v){ m_vars[v] = NULL; }
    				void free(int v){
    					// free memory, if this was the last referer
    					m_vars[v]->release();
    
    					// remove variable from heap
    					remove(v);
    				}
    				void insert(int v, Variable* var){
    					// check if we've reached the quota
    					if ( v >= m_vars.capacity() ){
    						// reserve more space for this heap
    						m_vars.reserve( m_vars.capacity() + m_capacity );
    					}
    
    					// insert variable
    					m_vars[v] = var;
    
    					// increment referers to this variable
    					var->addRef();
    				}
    
    			private:
    
    				std::vector< Variable* > m_vars;
    				const size_type m_capacity;
    				const int m_index;
    			};
    		}
    	}
    }
    
    #endif

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Well... size_type needs <string>. That's for sure.

    Why int is being reported as an error though is totally unknown to me. Makes no sense.

    Also, you can't do this when Variable has only been forward declared:

    Code:
    m_vars[v]->release();
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    It's possible, with this being simply a function declaration, that the error that should have been flagged at size_type has got the parser confused and it is interpreting index as a type. Thus making int extraneous.

    Once you #include <string> and change the code to read std::size_type capacity, the error will go away.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    Registered User Osaou's Avatar
    Join Date
    Nov 2004
    Location
    Stockholm, Sweden
    Posts
    69
    Hm... so <string> is required for size_type? But according to cppreference.com the vector class has a capacity constructor taking a size_type argument...

    Anyway, I tried including <string> but with no luck.

    This really is weird. I'm beginning to think the perpetrator is VSC++ 2005... this is after all the first project I'm building since upgrading from 2003...

    Either way, any response from someone who might know what the problem is is welcomed. =)

  5. #5
    Registered User Osaou's Avatar
    Join Date
    Nov 2004
    Location
    Stockholm, Sweden
    Posts
    69
    Heh, I edited my code to prefix size_type with "std::", and now it says "'size_type' : is not a member of 'std'"... =S
    Yes, <string> is included.

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    I'm sorry my bad. it's not std.

    You should scope with with whatever container you are using. a vector of ints for instance would have it scoped as vector<int>::size_type. A string as string::size_type.

    I believe what you wanted to have capacity declared as was:

    Code:
    std::vector< Variable* >::size_type capacity;
    you should also make this change to m_capacity
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    Registered User Osaou's Avatar
    Join Date
    Nov 2004
    Location
    Stockholm, Sweden
    Posts
    69
    Yeah, I checked the vector file locally, and later the standard and deduced this.
    Thanks for the help, man. =)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Problem creating dll with gcc/minGW
    By 6tr6tr in forum C++ Programming
    Replies: 1
    Last Post: 04-03-2008, 02:19 PM
  3. Creating DLL in DevC++
    By kkchennai in forum C Programming
    Replies: 6
    Last Post: 03-17-2006, 05:30 AM
  4. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  5. VCL and DLL class problem
    By borland_man in forum C++ Programming
    Replies: 1
    Last Post: 02-13-2002, 11:07 AM