Can I get some help with this?
Tyler Wrobel

I am running Ubuntu the most recent 16.04 LTS release. Here is my source code for my library I am trying to build, I will probably implement as an object file later but I am compiling for debugging and functions checking now and getting alot of wierd errors. I am using G++ on linux and emacs to build.

Source code:
#include<iostream>
#include<string>
using namespace std;
void vo_Lcout(string i_string){
cout<<(i_string);
cout<<endl;
}
template <class myType>
myType sL_cout (myType instance_a){
cout<<(instance_a);
cout<<endl;
}
template <class myType, class multiplier>
myType mL_cout (myType instance_a, multiplier b){
for(int i=0;i!=b;i++){
cout<<(instance_a);
cout<<endl;
}
}
int main(){
vo_Lcout("Hello! from vo_Lcout");
sL_cout <string> ("Hello!");
mL_cout <string,int> ("Hello!", 3);
return 0;
}

And here is the wild output from exe file(a.out):
Hello! from vo_Lcout
Hello!
*** Error in `./a.out': double free or corruption (fasttop): 0x0000000001eecc20 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f2754a297e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x7fe0a)[0x7f2754a31e0a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f2754a3598c]
./a.out[0x400c62]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f27549d2830]
./a.out[0x400ac9]
======= Memory map: ========
00400000-00402000 r-xp 00000000 00:2b 403228 /home/linux/notes/a.out
00601000-00602000 r--p 00001000 00:2b 403228 /home/linux/notes/a.out
00602000-00603000 rw-p 00002000 00:2b 403228 /home/linux/notes/a.out
01edb000-01f0d000 rw-p 00000000 00:00 0 [heap]
7f2750000000-7f2750021000 rw-p 00000000 00:00 0
7f2750021000-7f2754000000 ---p 00000000 00:00 0
7f27546a9000-7f27547b1000 r-xp 00000000 fd:01 812942 /lib/x86_64-linux-gnu/libm-2.23.so
7f27547b1000-7f27549b0000 ---p 00108000 fd:01 812942 /lib/x86_64-linux-gnu/libm-2.23.so
7f27549b0000-7f27549b1000 r--p 00107000 fd:01 812942 /lib/x86_64-linux-gnu/libm-2.23.so
7f27549b1000-7f27549b2000 rw-p 00108000 fd:01 812942 /lib/x86_64-linux-gnu/libm-2.23.so
7f27549b2000-7f2754b71000 r-xp 00000000 fd:01 812944 /lib/x86_64-linux-gnu/libc-2.23.so
7f2754b71000-7f2754d71000 ---p 001bf000 fd:01 812944 /lib/x86_64-linux-gnu/libc-2.23.so
7f2754d71000-7f2754d75000 r--p 001bf000 fd:01 812944 /lib/x86_64-linux-gnu/libc-2.23.so
7f2754d75000-7f2754d77000 rw-p 001c3000 fd:01 812944 /lib/x86_64-linux-gnu/libc-2.23.so
7f2754d77000-7f2754d7b000 rw-p 00000000 00:00 0
7f2754d7b000-7f2754d91000 r-xp 00000000 fd:01 789047 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f2754d91000-7f2754f90000 ---p 00016000 fd:01 789047 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f2754f90000-7f2754f91000 rw-p 00015000 fd:01 789047 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f2754f91000-7f2755103000 r-xp 00000000 fd:01 143070 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f2755103000-7f2755303000 ---p 00172000 fd:01 143070 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f2755303000-7f275530d000 r--p 00172000 fd:01 143070 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f275530d000-7f275530f000 rw-p 0017c000 fd:01 143070 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f275530f000-7f2755313000 rw-p 00000000 00:00 0
7f2755313000-7f2755339000 r-xp 00000000 fd:01 812945 /lib/x86_64-linux-gnu/ld-2.23.so
7f2755514000-7f2755519000 rw-p 00000000 00:00 0
7f2755535000-7f2755538000 rw-p 00000000 00:00 0
7f2755538000-7f2755539000 r--p 00025000 fd:01 812945 /lib/x86_64-linux-gnu/ld-2.23.so
7f2755539000-7f275553a000 rw-p 00026000 fd:01 812945 /lib/x86_64-linux-gnu/ld-2.23.so
7f275553a000-7f275553b000 rw-p 00000000 00:00 0
7ffc63800000-7ffc63821000 rw-p 00000000 00:00 0 [stack]
7ffc63908000-7ffc6390a000 r--p 00000000 00:00 0 [vvar]
7ffc6390a000-7ffc6390c000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Aborted (core dumped)

LennyLen

Did you ignore the warnings, or turn them, off?

||=== Build: Debug in Wrobel (compiler: GNU GCC Compiler) ===|
E:\Source Code\Wrobel\main.cpp||In instantiation of 'myType sL_cout(myType) [with myType = std::__cxx11::basic_string<char>]':|
E:\Source Code\Wrobel\main.cpp|25|required from here|
E:\Source Code\Wrobel\main.cpp|14|warning: no return statement in function returning non-void [-Wreturn-type]|
E:\Source Code\Wrobel\main.cpp||In instantiation of 'myType mL_cout(myType, multiplier) [with myType = std::__cxx11::basic_string<char>; multiplier = int]':|
E:\Source Code\Wrobel\main.cpp|26|required from here|
E:\Source Code\Wrobel\main.cpp|21|warning: no return statement in function returning non-void [-Wreturn-type]|
||=== Build finished: 0 error(s), 6 warning(s) (0 minute(s), 1 second(s)) ===|
||=== Run: Debug in Wrobel (compiler: GNU GCC Compiler) ===|

Fix those, then try again.

Tyler Wrobel

I decided to go this route so I could avoid any silly problems. Converted all functions to pointers. Works like a charm.

#include<iostream>
#include<string>
#define msgplain1 "uninitiated"
#define usramt 1
#define N N_function()
using namespace std;
template <class myType>
myType *S (myType instance_a,bool line_Space){
if(line_Space==true){
cout<<(instance_a);
cout<<endl;
}
else{
cout<<(instance_a);
}
}
template <class myType>
myType *S (myType instance_a){
cout<<(instance_a);
cout<<endl;
}
template <class myType, class multiplier>
myType *ML (myType instance_a, multiplier b){
for(int i=0;i!=b;i++){
S(instance_a,true);
}
}
void *N_function (){
cout<<endl;
}
string user1 = msgplain1;
string user2 = msgplain1;
int varq = usramt;
int main(int argc, char *argv[]){
S <string> (user1);
ML <string,int> (user2, varq);
N;
return 0;
}

Thread #616844. Printed from Allegro.cc