Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6988029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:01:01+00:00 2026-05-27T19:01:01+00:00

The following simple program segfaults on my mac (Lion) running gcc 4.2.1: #include <iostream>

  • 0

The following simple program segfaults on my mac (Lion) running gcc 4.2.1:

#include <iostream>

using namespace std;
struct A{
  friend std::ostream& operator << (std::ostream& os, const A& a) {
    os << 3 << endl;
  }
};

template <typename T>
T f() { return T();}

int f() { return 2;}


int main() {
  cout << f() << endl;

  A a= f<A>();
  cout << a << endl;
}

When I run the program, I get:

 ./a.out
2
3
Segmentation fault: 11

When I do a stacktrace, I get:

(gdb) run

Starting program: a.out 
unable to read unknown load command 0x24
unable to read unknown load command 0x26
2
3

Program received signal SIGSEGV, Segmentation fault.
0x00007fff8b84fa49 in ?? ()
(gdb) bt
#0  0x00007fff8b84fa49 in ?? ()
#1  0x00007fff665c1ae8 in ?? ()
#2  0x0000000000000000 in ?? ()

The backtrace has no useful information (anyone know why?). This works
fine in linux.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:01:02+00:00Added an answer on May 27, 2026 at 7:01 pm

    Let’s make it clearer what happens

    (cout << a) << endl;
    

    You forgot a return in your operator<<.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am compiling the following simple program with g++-4.6.1 --std=c++0x : #include <algorithm> struct
Very simple question, I made the following program : #include <stdlib.h> int main(int argc,
I'm using MinGw on Windows 7. The following simple program compiles fine, but the
I'm trying to get the following simple C++ program to compile: #include <stdio.h> #include
Using glew, I'm trying to link the simple program #include </usr/include/GL/glew.h> int main (int
i have the following program. #include <iostream> #include <vector> #include <algorithm> #include <cassert> #include
Consider a simple program in C++: #include <iostream> class link {}; int main() {
I am trying to reverse a C style string using the following simple program.
Given the following simple program: import wx class TestDraw(wx.Panel): def __init__(self,parent=None,id=-1): wx.Panel.__init__(self,parent,id,style=wx.TAB_TRAVERSAL) self.SetBackgroundColour(#FFFFFF) self.Bind(wx.EVT_PAINT,self.onPaint)
Based on the following simple program the bitwise left shift operator works only for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.