Page 1 of 1
trouble compiling template class in linux
Posted: Sat Jan 19, 2008 12:51 pm
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?
Posted: Sat Jan 19, 2008 1:05 pm
by Alboin
Care to provide some code?
Posted: Sat Jan 19, 2008 3:53 pm
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
???????????
Posted: Sat Jan 19, 2008 6:30 pm
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?
Posted: Sat Jan 19, 2008 6:49 pm
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.
Posted: Sat Jan 19, 2008 7:19 pm
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?
Posted: Sat Jan 19, 2008 7:34 pm
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.
Posted: Sun Jan 20, 2008 3:41 am
by bluecode
You should fix warnings and not ignore them
, unless you
really know what you are doing and you have a
really good reason why you don't fix it).
Posted: Sun Jan 20, 2008 5:57 am
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.
Posted: Mon Jan 21, 2008 3:24 am
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