Author Topic: Template compilation with v1rc2  (Read 5454 times)

Offline jmeuf

  • Multiple posting newcomer
  • *
  • Posts: 18
Template compilation with v1rc2
« on: March 29, 2007, 02:58:09 pm »
Hi,

I'm trying to compile the following code:


Code
#include <vector>

template <class T>
class ListModule
{
    public:
        ListModule();
        ~ListModule();

    protected:

    private:
        vector<T>   _List;
        vector<T>::iterator _It;  // << Error is here
};

and get a message at compilation: Error : expected ';' before "_It"
I compile under C::B v1rc2 using the gnu compilers.

Is it due to the compiler (did you also get such an error) or is it my mistake (I'm not so familiar with templates...)?

Thanks.

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: Template compilation with v1rc2
« Reply #1 on: March 29, 2007, 03:15:43 pm »
First, this question is compiler-related rather than Code::Blocks related, so it would be appropriate to ask this question at a forum for general C++ programming help rather than here.
Second, the exact code you posted will raise a compiler error at the first declaration of vector rather than the second, because vector hasn't been qualified with the std namespace.
So make sure that the code you post at whichever general programming help forum you choose actually does exhibit whatever error you're getting.

Cheers,
JohnE / TDM

P.S. -- Even if the question were C::B-related, you'd only be told to download a nightly build. Code::Blocks has come a long way since RC2.
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Offline jmeuf

  • Multiple posting newcomer
  • *
  • Posts: 18
Re: Template compilation with v1rc2
« Reply #2 on: March 29, 2007, 04:38:29 pm »
Ok thanks for your advice. I will test that on a nightly.

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: Template compilation with v1rc2
« Reply #3 on: March 29, 2007, 05:37:25 pm »
Ok thanks for your advice. I will test that on a nightly.
In case you didn't understand me the first time:
Your problem is compiler-related, not Code::Blocks-related. Code::Blocks has nothing to do with your code causing errors when compiled. Whether code can compile is determined by (1) the code's correctness (2) according to the compiler being used, and upgrading C::B will change neither.
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Offline jmeuf

  • Multiple posting newcomer
  • *
  • Posts: 18
Re: Template compilation with v1rc2
« Reply #4 on: March 29, 2007, 07:36:30 pm »
As I could see it in the content of nightly build distributions, the Mingw compiler also evolves, and not only the GUI. Am I correct?

Concerning the <vector> declaration, the std is already resolved in my code, and the first declaration (the vector, not the iterator) compiles properly.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Template compilation with v1rc2
« Reply #5 on: March 29, 2007, 07:41:13 pm »
Code::Blocks and MinGW are two different projects.

Code::Blocks is an IDE which creates an connection between user and compiler (MinGW and other compilers).
Be a part of the solution, not a part of the problem.