trouble compiling template class in linux

Programming, for all ages and all languages.
Post Reply
dudeman
Posts: 21
Joined: Tue Jan 15, 2008 12:30 pm

trouble compiling template class in linux

Post by dudeman »

when I compile my template class in Windows using MinGW, everything works fine, when I compile the same exact thing in Linux, g++ complains wherever I allocate new memory...

any ideas?
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post by Alboin »

Care to provide some code?
C8H10N4O2 | #446691 | Trust the nodes.
dudeman
Posts: 21
Joined: Tue Jan 15, 2008 12:30 pm

Post by dudeman »

Code: Select all

template <typename T> class List{
    
    private:
        class Node{
            public:
                Node *next, *prev;
                T data;
                Node(const T& d, Node* n = 0, Node* p = 0):data(d),next(n),prev(p){};
        };
        
        Node *head, *tail;
    
    public:
        List<T>(const T&);
};

template <typename T> List<T>::List(const T& d){
    head = tail = new Node(d);
}
After stripping my class down to what you see here, I still get the following error:

Code: Select all

In constructor "List<T>::Node::Node(const T&, List<T>::Node*, List<T>::Node*)[with T = int]':
instantiated from "List<T>::List(const T&)[with T = int]'
Here's main:

Code: Select all

#include "list.h"
int main(){
    List<int> m_list(5);
    return 0;
}
Like I said this compiles no problems in windows w/mingw, but for some reason on my ubuntu system, I get the errors
???????????
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

In constructor "List<T>::Node::Node(const T&, List<T>::Node*, List<T>::Node*)[with T = int]':
instantiated from "List<T>::List(const T&)[with T = int]'
Errr... that's not an error - usually you get the "in ... " bit, the "instantiated from ..." bit, then the actual error bit!!

Care to elaborate further?
dudeman
Posts: 21
Joined: Tue Jan 15, 2008 12:30 pm

Post by dudeman »

no you're right, it is really strage. that's the message i'm getting from the geany ide when i compile, it will compile fine i guess in my terminal, but when i execute, it seg faults...

i dunno, i'm just frustrated because everything else in linux works beautifully.
dudeman
Posts: 21
Joined: Tue Jan 15, 2008 12:30 pm

Post by dudeman »

yea, i guess i'm just getting a lot of warnings, the seg fault was unrelated.

geez though, i wish i could turn the compiler down from "super-paranoid" to "normal", hehe

isn't there an option like -permissive or something like that?

right now i'm only compiling w/ -Wall and -Wextra, anything else i can do to relax things a bit?
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post by Alboin »

dudeman wrote:right now i'm only compiling w/ -Wall and -Wextra, anything else i can do to relax things a bit?
'w/' is 'with', right? Last time I checked -Wall and -Wextra turned on warnings. It doesn't turn them off.

I would suggest you keep them on, however, even if they are annoying at times.
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
bluecode
Member
Member
Posts: 202
Joined: Wed Nov 17, 2004 12:00 am
Location: Germany
Contact:

Post by bluecode »

You should fix warnings and not ignore them :roll: , unless you really know what you are doing and you have a really good reason why you don't fix it).
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

/agree bluecode. Warnings are there for a reason - be it deprecated behaviour or common newbie mistakes, they can point out stupid errors in your code before it seg faults.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

I tend to compile with -Werror so I can't go on unless all warnings are fixed. Have a look at the Makefile tutorial by Solar. There is a long list of -W flags which you can use. I tend to use all the ones applicable to C++. As suggested in the article, make sure you enable them one at a time!

Cheers,
Adam
Post Reply