error: expected primary-expression before ‘,’ token ... (only on linux)

Discussion in 'C++' started by carl, Dec 5, 2009.

  1. carl

    carl Guest

    I have a template function that I call like this:

    V testSize;
    F image = getImage();
    util.computeSize<V, I, P>(testSize, image);

    But I get this error:

    error: expected primary-expression before ‘,’ token

    util is an instance of:

    typedef MyUtil<I, M, T, D> UtilType;
    UtilType util;

    Which is a public field in my class. As can be seen I pass template
    parameters (V and P) to the function that I do not pass to the class, could
    this be the cause?

    The wierd thing is that it compile fine in Visual Studio on windows Vista
    but it gives the above error when I compile it on Ubuntu Linux.

    Any ideas on what I am doing wrong?
     
    carl, Dec 5, 2009
    #1
    1. Advertising

  2. carl

    Ian Collins Guest

    carl wrote:
    > I have a template function that I call like this:
    >
    > V testSize;
    > F image = getImage();
    > util.computeSize<V, I, P>(testSize, image);
    >
    > But I get this error:
    >
    > error: expected primary-expression before ‘,’ token
    >
    > util is an instance of:
    >
    > typedef MyUtil<I, M, T, D> UtilType;
    > UtilType util;
    >
    > Which is a public field in my class. As can be seen I pass template
    > parameters (V and P) to the function that I do not pass to the class,
    > could this be the cause?
    >
    > The wierd thing is that it compile fine in Visual Studio on windows
    > Vista but it gives the above error when I compile it on Ubuntu Linux.
    >
    > Any ideas on what I am doing wrong?


    Not posting enough information!

    Please post a minimal test case that shows your problem.

    --
    Ian Collins
     
    Ian Collins, Dec 5, 2009
    #2
    1. Advertising

  3. carl

    Jonathan Lee Guest

    Re: error: expected primary-expression before ‘,’ token ... (only on linux)

    On Dec 5, 5:56 pm, "carl" <carl@.com> wrote:
    > I have a template function that I call like this:
    >
    >     V testSize;
    >     F image = getImage();
    >     util.computeSize<V, I, P>(testSize, image);
    >
    > But I get this error:
    >
    > error: expected primary-expression before ‘,’ token


    Can't tell from what you posted, but V isn't a macro for
    a scoped class name is it? The only time I've had that
    error is when I've done something like

    myclass.somefunc<::std::string, ::std::string>(...)

    where the string "<::" doesn't parse. Putting a space in
    (i.e., "< ::") solves the problem (or, simply not using
    global scope resolution but that's besides the point).

    That's my only guess. Or "testSize" isn't successfully
    declared, but you'd have an error preceding the one you
    described.

    --Jonathan
     
    Jonathan Lee, Dec 5, 2009
    #3
  4. carl

    carl Guest

    "Ian Collins" <> wrote in message
    news:...
    > carl wrote:
    >> I have a template function that I call like this:
    >>
    >> V testSize;
    >> F image = getImage();
    >> util.computeSize<V, I, P>(testSize, image);
    >>
    >> But I get this error:
    >>
    >> error: expected primary-expression before ‘,’ token
    >>
    >> util is an instance of:
    >>
    >> typedef MyUtil<I, M, T, D> UtilType;
    >> UtilType util;
    >>
    >> Which is a public field in my class. As can be seen I pass template
    >> parameters (V and P) to the function that I do not pass to the class,
    >> could this be the cause?
    >>
    >> The wierd thing is that it compile fine in Visual Studio on windows Vista
    >> but it gives the above error when I compile it on Ubuntu Linux.
    >>
    >> Any ideas on what I am doing wrong?

    >
    > Not posting enough information!
    >
    > Please post a minimal test case that shows your problem.
    >
    > --
    > Ian Collins




    The call to the failing template function is made from the function
    setup() in the class Components:


    #include "my_types.h"

    template<unsigned int D=3>
    class Components{
    public:
    ....
    ....
    // Types
    typedef typename MyTypes::VectorType V;
    typedef typename MyTypes::ImageType F;
    typedef typename MyTypes::Image2Type I;
    typedef typename MyTypes::TransformType T;
    typedef typename MyTypes::MeshType M;
    typedef typename MyTypes::pointType P;
    typedef MyUtil<I, M, T, D> UtilType;

    // Instances
    UtilType util;


    void setup() {
    V testSize;
    F image;
    util.computeSize<V, I, P> (testSize, image);

    ....

    }






    'util' is an instance of MyUtil which contains the failing function
    'computeSize()' declared like this:


    #include "my_types.h"

    template<typename I, typename M, typename T, unsigned int D=3>
    class MyUtil {
    public:
    typedef typename MyTypes::VectorType V;

    ...
    ...

    template<typename V, typename I, typename P>
    void computeSize(V & imageSize, typename I::pointer image) {

    ....

    }



    I have tried to remove the typedef:

    typedef typename MyTypes::VectorType V;

    from the MyUtil class and move it to the template declaration like this:

    template<typename V, typename I, typename M, typename T, unsigned int D=3>
    class MyUtil {


    And change the code that creates the MyUtil class accordingly, but
    that does not solve the problem.

    But why does this work fine on windows and not in linux?
     
    carl, Dec 5, 2009
    #4
  5. carl

    carl Guest

    "carl" <carl@.com> wrote in message
    news:4b1aeec2$0$277$...
    >
    > "Ian Collins" <> wrote in message
    > news:...
    >> carl wrote:
    >>> I have a template function that I call like this:
    >>>
    >>> V testSize;
    >>> F image = getImage();
    >>> util.computeSize<V, I, P>(testSize, image);
    >>>
    >>> But I get this error:
    >>>
    >>> error: expected primary-expression before ‘,’ token
    >>>
    >>> util is an instance of:
    >>>
    >>> typedef MyUtil<I, M, T, D> UtilType;
    >>> UtilType util;
    >>>
    >>> Which is a public field in my class. As can be seen I pass template
    >>> parameters (V and P) to the function that I do not pass to the class,
    >>> could this be the cause?
    >>>
    >>> The wierd thing is that it compile fine in Visual Studio on windows
    >>> Vista but it gives the above error when I compile it on Ubuntu Linux.
    >>>
    >>> Any ideas on what I am doing wrong?

    >>
    >> Not posting enough information!
    >>
    >> Please post a minimal test case that shows your problem.
    >>
    >> --
    >> Ian Collins

    >
    >
    >
    > The call to the failing template function is made from the function
    > setup() in the class Components:
    >
    >
    > #include "my_types.h"
    >
    > template<unsigned int D=3>
    > class Components{
    > public:
    > ....
    > ....
    > // Types
    > typedef typename MyTypes::VectorType V;
    > typedef typename MyTypes::ImageType F;
    > typedef typename MyTypes::Image2Type I;
    > typedef typename MyTypes::TransformType T;
    > typedef typename MyTypes::MeshType M;
    > typedef typename MyTypes::pointType P;
    > typedef MyUtil<I, M, T, D> UtilType;
    >
    > // Instances
    > UtilType util;
    >
    >
    > void setup() {
    > V testSize;
    > F image;
    > util.computeSize<V, I, P> (testSize, image);
    >
    > ....
    >
    > }
    >
    >
    >
    >
    >
    >
    > 'util' is an instance of MyUtil which contains the failing function
    > 'computeSize()' declared like this:
    >
    >
    > #include "my_types.h"
    >
    > template<typename I, typename M, typename T, unsigned int D=3>
    > class MyUtil {
    > public:
    > typedef typename MyTypes::VectorType V;
    >
    > ...
    > ...
    >
    > template<typename V, typename I, typename P>
    > void computeSize(V & imageSize, typename I::pointer image) {
    >
    > ....
    >
    > }
    >
    >
    >
    > I have tried to remove the typedef:
    >
    > typedef typename MyTypes::VectorType V;
    >
    > from the MyUtil class and move it to the template declaration like this:
    >
    > template<typename V, typename I, typename M, typename T, unsigned int
    > D=3>
    > class MyUtil {
    >
    >
    > And change the code that creates the MyUtil class accordingly, but
    > that does not solve the problem.
    >
    > But why does this work fine on windows and not in linux?
    >
    >
    >
    >
    >




    Hm now I have tried to move the types to the MyUtil class and now the
    function computeSize(...) is a simple non-template function:

    void computeSize(V & imageSize, typename I::pointer image) {

    }

    But are there any special rules for calling a non-template function in a
    template class that I am missing?
     
    carl, Dec 6, 2009
    #5
  6. carl

    carl Guest

    Ha the error was that the vector type was a float in the one module and a
    double in the other. Is that not a pretty nasty thing to NOT to throw an
    error for when using th Visual Studio compiler?




    "carl" <carl@.com> wrote in message
    news:4b1af62b$0$283$...
    >
    > "carl" <carl@.com> wrote in message
    > news:4b1aeec2$0$277$...
    >>
    >> "Ian Collins" <> wrote in message
    >> news:...
    >>> carl wrote:
    >>>> I have a template function that I call like this:
    >>>>
    >>>> V testSize;
    >>>> F image = getImage();
    >>>> util.computeSize<V, I, P>(testSize, image);
    >>>>
    >>>> But I get this error:
    >>>>
    >>>> error: expected primary-expression before ‘,’ token
    >>>>
    >>>> util is an instance of:
    >>>>
    >>>> typedef MyUtil<I, M, T, D> UtilType;
    >>>> UtilType util;
    >>>>
    >>>> Which is a public field in my class. As can be seen I pass template
    >>>> parameters (V and P) to the function that I do not pass to the class,
    >>>> could this be the cause?
    >>>>
    >>>> The wierd thing is that it compile fine in Visual Studio on windows
    >>>> Vista but it gives the above error when I compile it on Ubuntu Linux.
    >>>>
    >>>> Any ideas on what I am doing wrong?
    >>>
    >>> Not posting enough information!
    >>>
    >>> Please post a minimal test case that shows your problem.
    >>>
    >>> --
    >>> Ian Collins

    >>
    >>
    >>
    >> The call to the failing template function is made from the function
    >> setup() in the class Components:
    >>
    >>
    >> #include "my_types.h"
    >>
    >> template<unsigned int D=3>
    >> class Components{
    >> public:
    >> ....
    >> ....
    >> // Types
    >> typedef typename MyTypes::VectorType V;
    >> typedef typename MyTypes::ImageType F;
    >> typedef typename MyTypes::Image2Type I;
    >> typedef typename MyTypes::TransformType T;
    >> typedef typename MyTypes::MeshType M;
    >> typedef typename MyTypes::pointType P;
    >> typedef MyUtil<I, M, T, D> UtilType;
    >>
    >> // Instances
    >> UtilType util;
    >>
    >>
    >> void setup() {
    >> V testSize;
    >> F image;
    >> util.computeSize<V, I, P> (testSize, image);
    >>
    >> ....
    >>
    >> }
    >>
    >>
    >>
    >>
    >>
    >>
    >> 'util' is an instance of MyUtil which contains the failing function
    >> 'computeSize()' declared like this:
    >>
    >>
    >> #include "my_types.h"
    >>
    >> template<typename I, typename M, typename T, unsigned int D=3>
    >> class MyUtil {
    >> public:
    >> typedef typename MyTypes::VectorType V;
    >>
    >> ...
    >> ...
    >>
    >> template<typename V, typename I, typename P>
    >> void computeSize(V & imageSize, typename I::pointer image) {
    >>
    >> ....
    >>
    >> }
    >>
    >>
    >>
    >> I have tried to remove the typedef:
    >>
    >> typedef typename MyTypes::VectorType V;
    >>
    >> from the MyUtil class and move it to the template declaration like this:
    >>
    >> template<typename V, typename I, typename M, typename T, unsigned int
    >> D=3>
    >> class MyUtil {
    >>
    >>
    >> And change the code that creates the MyUtil class accordingly, but
    >> that does not solve the problem.
    >>
    >> But why does this work fine on windows and not in linux?
    >>
    >>
    >>
    >>
    >>

    >
    >
    >
    > Hm now I have tried to move the types to the MyUtil class and now the
    > function computeSize(...) is a simple non-template function:
    >
    > void computeSize(V & imageSize, typename I::pointer image) {
    >
    > }
    >
    > But are there any special rules for calling a non-template function in a
    > template class that I am missing?
     
    carl, Dec 6, 2009
    #6
  7. carl schrieb:
    > I have a template function that I call like this:
    >
    > V testSize;
    > F image = getImage();
    > util.computeSize<V, I, P>(testSize, image);
    >
    > But I get this error:
    >
    > error: expected primary-expression before ‘,’ token


    The compiler can't parse the expression, so if this code is in a
    template function, most likely the compiler doesn't know that
    computeSize is a template.

    Just like you sometimes need to add the "typename" keyword to tell the
    compiler that an identifier is a type, you need to add the "template"
    keyword to tell him that something is a template, i.e.:

    util.template computeSize<V, I, P>(testSize, image);

    Since the type of util depends on a template parameter, the compiler
    can't immediately determine that one of its members is a template or not.

    For any code like this that doesn't work, the best way is to post a
    minimal but compilable code example that shows the error. If you only
    post those code extracts with important details replaced by "...", it is
    really hard to guess the error. Please read the FAQ:
    http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.8

    PS: Why isn't this "typename" and "template" issue already in the FAQ?

    --
    Thomas
     
    Thomas J. Gritzan, Dec 6, 2009
    #7
  8. Thomas J. Gritzan wrote:

    > carl schrieb:
    >> I have a template function that I call like this:
    >>
    >> V testSize;
    >> F image = getImage();
    >> util.computeSize<V, I, P>(testSize, image);
    >>
    >> But I get this error:
    >>
    >> error: expected primary-expression before ‘,’ token

    >
    > The compiler can't parse the expression, so if this code is in a
    > template function, most likely the compiler doesn't know that
    > computeSize is a template.
    >
    > Just like you sometimes need to add the "typename" keyword to tell the
    > compiler that an identifier is a type, you need to add the "template"
    > keyword to tell him that something is a template, i.e.:
    >
    > util.template computeSize<V, I, P>(testSize, image);
    >
    > Since the type of util depends on a template parameter, the compiler
    > can't immediately determine that one of its members is a template or not.
    >
    > For any code like this that doesn't work, the best way is to post a
    > minimal but compilable code example that shows the error. If you only
    > post those code extracts with important details replaced by "...", it is
    > really hard to guess the error. Please read the FAQ:
    > http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.8
    >
    > PS: Why isn't this "typename" and "template" issue already in the FAQ?
    >


    It's in the template faq: http://womble.decadentplace.org.uk/c /template-
    faq.html
     
    Johannes Schaub (litb), Dec 6, 2009
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bubzilla
    Replies:
    2
    Views:
    965
    bubzilla
    Sep 25, 2006
  2. Replies:
    3
    Views:
    3,382
    Earl Purple
    Oct 5, 2006
  3. Lawrence Spector
    Replies:
    8
    Views:
    591
    Lawrence Spector
    Jul 12, 2007
  4. =?Utf-8?B?Y2FzaGRlc2ttYWM=?=

    This is an unexpected token. The expected token is 'NAME'

    =?Utf-8?B?Y2FzaGRlc2ttYWM=?=, Jul 13, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    825
    =?Utf-8?B?Y2FzaGRlc2ttYWM=?=
    Jul 13, 2007
  5. Dariusz My¶liwiec

    [ERROR] Expected expression before ';' token

    Dariusz My¶liwiec, Jan 20, 2013, in forum: C Programming
    Replies:
    4
    Views:
    924
    Tim Rentsch
    Jan 20, 2013
Loading...

Share This Page